简体   繁体   中英

Laravel 5.3 Rest API Setup

I am building Backend for my Mobile App in Laravel 5.3. I ll be sending/receiving and updating data using laravel REST API.

I want Few data/info to be provided to Guest user who is using my mobile app. and few info/data to registered users.

I want to make use of REST API

I tried dingo which is recommended by many people. But problem is it is not supported with laravel 5.3 and its documentation is also not upto date.

Can anyone please suggest any package or code tutorial that i can follow to achieve my goal.

Definitely recommend checking out Laravel Passport and upgrading to 5.4. Laravel Passport . That'll be the best option going forward as that's the way Laravel is moving towards. Other libraries will die off for laravel support as this moves to popularity.

I can suggest PHP-CRUD-API (I'm the author). Below is the short tutorial to get started.

In order to add the automatic API library you need to run:

php composer.phar require symfony/psr-http-message-bridge
php composer.phar require zendframework/zend-diactoros
php composer.phar require mevdschee/php-crud-api

Change the "routes/api.php" to the following content to define our new API route:

<?php

use Psr\Http\Message\ServerRequestInterface;
use Tqdev\PhpCrudApi\Api;
use Tqdev\PhpCrudApi\Config;

Route::any('/{any}', function (ServerRequestInterface $request) {
    $config = new Config([
        'username' => 'php-crud-api',
        'password' => 'php-crud-api',
        'database' => 'php-crud-api',
        'basePath' => '/api',
    ]);
    $api = new Api($config);
    $response = $api->handle($request);
    return $response;
})->where('any', '.*');

Replace the string "php-crud-api" in the above code to match the username, password and database of your setup (preferably reading them from environment variables). You should see your application running at:

http://127.0.0.1:8000/api/records/posts

Replace "posts" with the name of any table in your database. If everything works as expected, then you should see the contents of the table in JSON format.

source: https://tqdev.com/2019-automatic-rest-api-laravel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM