Lena LfPC
Lena LfPC

Reputation: 11

API Endpoint - Calling path/file.php works but doesn't by endpoint

I made a simple API with PHP

When I call it (Postman or script) with https://www.example.org/api/index_api.php it works. I get the return value.

When I call it (Postman or script) with https://www.example.org/api/ it doesn't.

Object sent

{
  "id": "alberto",
  "name": "test name naaame ",
  "email": "[email protected]"
}

index_api.php (simplified: here, I don't use $method):

<?php
header('Content-type: application/json; charset=utf-8');

$method = $_SERVER['REQUEST_METHOD'];
//
$input = json_decode(file_get_contents('php://input'), true);
$input = mb_convert_encoding($input, 'HTML-ENTITIES', "UTF-8");
//
echo json_encode(['3' => 'De vuelta de API : ' . $input['name'] ]);

I'd be really grateful to receive some help.

I tried a lot of URL rewrite rules in .htaccess, but no success.

When it's for myself, I use complete path but it's not an API. And I need to call it

Thanks by advance

Upvotes: 1

Views: 48

Answers (0)

Related Questions