I am using the Slim framework with PHP to create a RESTful API for my app. However, I assumed that the framework would have some way of creating easier JSON outputs rather than
Using Slim 3, I'm using this format:
get('/{id}', function ($request, $response, $args) {
$id = $request->getAttribute('id');
return $response->withJSON(
['id' => $id],
200,
JSON_UNESCAPED_UNICODE
);
});
On request "/123", result JSON with:
{
id: "123"
}
More infos read here.
[UPDATE]
Added second and third param to withJSON
. Second is The HTTP status code, and third is Json encoding options (best for especial chars and others, for example: print "ã" correctly)