Can anyone tell me if this is possible please? If I post a JSON request to a Lumen app (with Content-Type: application/json), I can't see a way to grab the input. In Laravel Framework, you can you "Input::", but Lumen only seems to have "Request" class and I can't see how to extract the JSON data easily. There's not so much info out there just yet... can anyone suggest how to do this? Thanks
If php / pdo can lumen can. Lumen is a php framework.
http://stackoverflow.com/questions/18354638/json-post-and-decode-array-to-php
If the json is not formatted correctly it will just silently fail to parse it
Thanks for the replies! I got it working now.
The answer I was looking for was to use the Request::json()->get method, to extract the JSON data from the request.
So, posting a request like this...
POST / HTTP/1.1
Host: localhost
Content-Type: application/json
{
"name": "dave"
}
...and accessing the data using something like...
$app->post('/', function() use ($app) {
dd(Request::json()->get('name'));
});
Maybe useful for someone else. Thanks!
I wrote about this topic - "How to Submit a JSON POST Request in Lumen" - https://medium.com/@paulredmond/how-to-submit-json-post-requests-to-lumen-666257fe8280
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community