Skip to content

Lumen

Lumen is a Laravel based micro-framework.

quicknote

serve the project: php -S localhost:8000 -t public

Tips

Make utf-8 charset for JSON response

To make charset to utf-8 for JSON response by default, set a new jsonResponse function in base controller, like:

protected function jsonResponse($data, $code = 200)
{
    return response()->json($data, $code,
        ['Content-Type' => 'application/json;charset=UTF-8', 'Charset' => 'utf-8'], JSON_UNESCAPED_UNICODE);
}

Then for response, return $this->jsonResponse($data);.

source: Laravel: Encode JSON responses in UTF-8 - Stack Overflow


$request in PUT route does not return input data

When testing with Postman\Insomnia, Lumen cannot get inputs from a PUT method endpoint, the request body is null.

Need to modify the request structure in API tool(Postman\Insomnia) to fix this issue, the request should encode in x-www-form-urlencode. Change the request structure in insomnia and this should work.

insomnia_put_request_structure

ref

Resources

Tutorial