Giter VIP home page Giter VIP logo

laravel-passport-rest-api-unit-testing's Introduction

laravel-passport-rest-API-unit-testing

User login and registraion, Blog CRUD with laravel Passport Rest API also with PHP unit-testing for the functionalities.

Installation : 
    composer require laravel/passport
    php artisan migrate
    php artisan passport:install

    //User Model

    use Laravel\Passport\HasApiTokens;
    HasApiTokens
    
    config/auth.php

            'guards' => [
                'web' => [
                    'driver' => 'session',
                    'provider' => 'users',

        ],

                'api' => [
                    'driver' => 'passport', // set this to passport
                    'provider' => 'users',
                    'hash' => false,
                ],
            ],


    php artisan serve

API end points :

    API Routes :

        Register

            Request : 

                    POST => http://127.0.0.1:8000/api/register
                    Form Body => email, password, name
                    File => app\Http\Controllers\API\AuthController.php
                    method => register

            Response : {
                            "user": {
                                "name": "name",
                                "email": "[email protected]",
                                "updated_at": "2024-01-17T11:01:40.000000Z",
                                "created_at": "2024-01-17T11:01:40.000000Z",
                                "id": 1
                            },
                            "access_token": "toekn here"
                        }

        Login

            Request:
                    POST => http://127.0.0.1:8000/api/login
                    Form Body => email, password
                    File => app\Http\Controllers\API\AuthController.php
                    method => login
            Response:   {
                          "access_token": " access_token"
                        }

    Blog :

        Create 

            Request : 
                    Post =>  http://127.0.0.1:8000/api/blog
                    Form Body => blog_title , blog_content
                    Auth => Bearer Token : access_token_generated_from_login

            Response :
                        {
                            "blog": {
                                "blog_title": "Hello World",
                                "blog_content": "Welcome",
                                "user_id": 1,
                                "updated_at": "2024-01-17T11:06:55.000000Z",
                                "created_at": "2024-01-17T11:06:55.000000Z",
                                "id": 1
                            },
                            "message": "Blog created successfully"
                        }

        View Blog List

            Request : 
                    Get =>  http://127.0.0.1:8000/api/blog
                    Auth => Bearer Token : access_token_generated_from_login
            Response :
                        {
                            "blogs": [
                                {
                                "id": 1,
                                "user_id": 1,
                                "blog_title": "Hello World",
                                "blog_content": "Welcome",
                                "created_at": "2024-01-17T11:06:55.000000Z",
                                "updated_at": "2024-01-17T11:06:55.000000Z"
                                }
                            ]
                       }

        Update 

            Request : 
                    PUT =>  http://127.0.0.1:8000/api/blog/1
                    Form Body => blog_title , blog_content
                    Auth => Bearer Token : access_token_generated_from_login

            Response :
                        {
                            "blog": {
                                "id": 1,
                                "user_id": 1,
                                "blog_title": "Hello World",
                                "blog_content": "Life is beautiful",
                                "created_at": "2024-01-17T11:06:55.000000Z",
                                "updated_at": "2024-01-17T11:17:44.000000Z"
                            },
                            "message": "Blog updated successfully"
                        }

        
        Delete
            Request : 
                    DELETE =>  http://127.0.0.1:8000/api/blog/1
                    Auth => Bearer Token : access_token_generated_from_login
            Response :
                        {
                          "message": "Blog deleted successfully"
                        }
            

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.