Coder Social home page Coder Social logo

slim-rest's Introduction

Slim 3 Rest API Prototype

Just a spare time project, for getting the rust off. This is in no way a production ready example.

You can use and get "inspired" by this project :D.

This project is as it is.

Important!!!

There is default admin user with username [email protected] and password Admin12345. This user should be removed as soon as you create your own admin user.

Use DELETE FROM users WHERE id = 1;.

Dependencies

  • lcobucci/jwt
  • sodium (install via PECL)
  • uses Sqlite 3

Development

  1. Init database
$ sqlite3 SlimRest.sqlite3 < init.sql
  1. Install dependencies
$ composer install [--no-dev]
  1. Start development server
$ composer start

Re-generate autoload dependencies

If you added or installed new dependencies you should run this command

$ composer dump-autoload

Run tests

$ composer test

API documentation

API Resources

POST /products

Example: http://localhost:8080/products

Request headers: - Content-Type: application/json - Authorization: Bearer <jwt_token> Request body:

{
    "name": "Product3",
    "price": "150.00",
    "discount": "15.00",
    "discountType": "variable"
}

Response body: None Response status: - Success: 201 - Error: 400 Response headers: Location: /products/[id]

GET /products/[id]

Example: http://localhost:8080/products/[id]

Request headers: - Authorization: Bearer <jwt_token>

Response body:

{
    "id": "3",
    "name": "Product3",
    "price": "150.00",
    "discount": "15.00",
    "discountType": "variable"
}

Response status: - Success: 200 - Error: 400

POST /bundles

Example: http://localhost:8080/bundles

Request headers: - Content-Type: application/json - Authorization: Bearer <jwt_token> Request body:

{
    "name": "Bundle1",
    "price": "100.00",
    "products": [2,3]
}

Response body: None Response status: - Success: 201 - Error: 400 Response headers: Location: /bundles/[id]

GET /bundles/[id]

Example: http://localhost:8080/bundles/[id]

Request headers: - Authorization: Bearer <jwt_token>

Response body:

{
    "id": "1",
    "name": "Bundle1",
    "price": "100.00"
}

Response status: - Success: 200 - Error: 400

GET /bundles/[id]/products

Example: http://localhost:8080/bundles/[id]/products

Request headers: - Authorization: Bearer <jwt_token>

Response body:

{
    "id": "1",
    "name": "Bundle1",
    "price": "100.00"
}

Response status: - Success: 200 - Error: 400

POST /orders

Example: http://localhost:8080/orders

Request headers: - Content-Type: application/json - Authorization: Bearer <jwt_token> Request body:

{
    "totalPrice": "100.00",
    "products": [2,3],
    "bundles": [1]
}

Response body: None Response status: - Success: 201 - Error: 400 Response headers: Location: /orders/[id]

GET /orders/[id]

Example: http://localhost:8080/orders/[id]

Request headers: - Authorization: Bearer <jwt_token>

Response body:

{
    "id": "4",
    "totalPrice": "430.00"
}

Response status: - Success: 200 - Error: 400

GET /orders/[id]/products

Example: http://localhost:8080/orders/[id]/products

Request headers: - Authorization: Bearer <jwt_token>

Response body:

[
    {
        "id": "1",
        "name": "Product1"
    },
    {
        "id": "2",
        "name": "Product2"
    },
    {
        "id": "3",
        "name": "Product3"
    }
]

Response status: - Success: 200 - Error: 400

GET /orders/[id]/bundles

Example: http://localhost:8080/orders/[id]/bundles

Request headers: - Authorization: Bearer <jwt_token>

Response body:

[
    {
        "id": "1",
        "name": "Bundle1"
    }
]

Response status: - Success: 200 - Error: 400

POST /roles

Example: http://localhost:8080/roles

Request headers: - Content-Type: application/json - Authorization: Bearer <jwt_token> Request body:

{
    "role": "admin"
}

Response body: None Response status: - Success: 201 - Error: 400 Response headers: Location: /roles/[id]

GET /roles/[id]

Example: http://localhost:8080/roles/[id]

Request headers: - Authorization: Bearer <jwt_token>

Response body:

{
    "id": "1",
    "role": "admin"
}

Response status: - Success: 200 - Error: 400

GET /users/[id]

Example: http://localhost:8080/users/[id]

Request headers: - Authorization: Bearer <jwt_token>

Response body:

{
    "id": "1",
    "username": "[email protected]"
}

Response status: - Success: 200 - Error: 400

GET /users/[id]/roles

Example: http://localhost:8080/users/[id]/roles

Request headers: - Authorization: Bearer <jwt_token>

Response body:

[
    {
        "id": "1",
        "role": "Role1"
    },
    {
        "id": "2",
        "role": "Role2"
    }
]

Response status: - Success: 200 - Error: 400

POST /users/[id]/roles/[id]

Example: http://localhost:8080/users/3/roles/1

Request headers: - Content-Type: application/json - Authorization: Bearer <jwt_token> Request body: None

Response body: None Response status: - Success: 200 - Error: 400

DELETE /users/[id]

Example: http://localhost:8080/users/3

Request headers: - Content-Type: application/json - Authorization: Bearer <jwt_token> Request body: None

Response body: None Response status: - Success: 200 - Error: 400

POST /auth/register

Example: http://localhost:8080/auth/register

Request headers: - Content-Type: application/json Request body:

{
    "username": "[email protected]",
    "password": "MyPassword12345"
}

Response body: None Response status: - Success: 201 - Error: 400 Response headers: Location: /users/[id]

POST /auth/login

Example: http://localhost:8080/auth/login

Request headers: - Content-Type: application/json Request body:

{
    "username": "[email protected]",
    "password": "MyPassword12345"
}

Response body:

<jwt_token>

Response status: - Success: 200 - Error: 400

slim-rest's People

Contributors

daniyel avatar

Watchers

 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.