Laravel has a very simple way to make APIs. This article will show you how to make these simple requests.
Get requests
To create a basic request, open routes/api.php
and create get request, the syntax looks like that
Route::get('/articles', function() {
return 'Articles';
});
This code will return a page with "Articles".
Return JSON
To return a simple JSON response simply use response()->json
Route::get('/user', function() {
return response()->json([ 'name' => 'John', ]);
});
Top comments (0)