DEV Community

Tarek Hassan
Tarek Hassan

Posted on

Making API requests in Laravel

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';
});
Enter fullscreen mode Exit fullscreen mode

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', ]);
});
Enter fullscreen mode Exit fullscreen mode

Discussion (0)