Coder Social home page Coder Social logo

pat-test's Introduction

API Documentation

Build Status coverage

This API uses POST and GET request to communicate and HTTP response codes to indenticate status and errors. All responses come in standard JSON. All requests must include a content-type of application/json and the body must be valid JSON.

Package for API Authentication

Laravel Passport for API authentication https://github.com/laravel/passport

Documentation URL

https://patricia-test-example.herokuapp.com/api/documentation

APP URL

https://patricia-test-example.herokuapp.com

Response Codes

Response Codes

200: Success
400: Bad request
401: Unauthorized
404: Cannot be found
405: Method not allowed
422: Unprocessable Entity
50X: Server Error

Error Codes Details

100: Bad Request
110: Unauthorized
120: User Authenticaion Invalid
130: Parameter Error
140: Item Missing
150: Conflict
160: Server Error

Register

You send: Your Registration datail. You get: An API-Token with wich you can make further actions.

Request:

POST /api/v1/register HTTP/1.1
Accept: application/json
Content-Type: application/json

{
    "name": "foo",
    "email": "example",
    "password": "1234567",
    "password_confirmation": "1234567"
}

Successful Response:

HTTP/1.1 201 Created
Server: My RESTful API
Content-Type: application/json

{
    "data": {
        "status": true,
        "message": "Account created successfully!",
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIzIiwianRpIjoiOWZmMzVjNzA3ZGI5NGJmMmIyNzQ5MzczMWM1Yjg3MzRlOTBmN2RhN",
        "token_type": "Bearer"
    }
}

Failed Response:

HTTP/1.1 400 Bad Request
Server: RESTful API
Content-Type: application/json

{
    "message": "Validation errors",
    "errors": {
        "email": [
            "The email has already been taken."
        ]
    },
    "status": false
}

Login

You send: Your login credentials. You get: An API-Token with wich you can make further actions.

Request:

POST /api/v1/login HTTP/1.1
Accept: application/json
Content-Type: application/json

{
    "username": "foo",
    "password": "1234567"
}

Successful Response:

HTTP/1.1 200 OK
Server: My RESTful API
Content-Type: application/json

{
    "data": {
        "status": true,
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIzIiwianRpIjoiMzAxY2VlMGM2ODk4NWE3ZDY5NzZiMzMxM2ZhZDI1ZDk2ODFiMzg0MWVmODc0MzExNDkzZjMyMDZhMDNiMzI0Z",
        "token_type": "Bearer"
    }
}

Failed Response:

HTTP/1.1 401 Unauthorized
Server: RESTful API
Content-Type: application/json

{
    "error": "Invalid Credentials",
    "status": false
}

Get User Details

You send: Your Pass the Authorization Token as Header to authenticate. You get: User details.

Request:

POST /api/v1/user/data HTTP/1.1
Accept: application/json
Content-Type: application/json

Successful Response:

HTTP/1.1 200 OK
Server: RESTful API
Content-Type: application/json

{
    "user": {
        "id": 11,
        "name": "example",
        "email": "[email protected]",
        "last_logged_in": "2020-09-22 19:16:11",
        "created_at": "2020-09-22T17:55:47.000000Z",
        "updated_at": "2020-09-22T19:16:11.000000Z"
    },
    "success": true
}

Failed Response:

HTTP/1.1 401 Unauthorized
Server: RESTful API
Content-Type: application/json

Unauthorized.

Logout

You send: Your Pass the Authorization Token as Header to authenticate. You get: Logout Message.

Request:

POST /api/v1/logout HTTP/1.1
Accept: application/json
Content-Type: application/json

Successful Response:

HTTP/1.1 200 OK
Server: RESTful API
Content-Type: application/json

{
    "message": "Successfully logged out",
    "succes": true
}

Failed Response:

HTTP/1.1 401 Unauthorized
Server: RESTful API
Content-Type: application/json

Unauthorized.

To run the Test

Register

vendor/bin/phpunit --filter=testNewUserRegistration

Login

vendor/bin/phpunit --filter=testUserLogin

Get User Data

vendor/bin/phpunit --filter=testGetUserData

Log User Out

vendor/bin/phpunit --filter=testLogUserOut

pat-test's People

Contributors

iamnotstatic avatar

Watchers

James Cloos avatar  avatar  avatar

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.