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.
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;
.
- lcobucci/jwt
- sodium (install via PECL)
- uses Sqlite 3
- Init database
$ sqlite3 SlimRest.sqlite3 < init.sql
- Install dependencies
$ composer install [--no-dev]
- Start development server
$ composer start
If you added or installed new dependencies you should run this command
$ composer dump-autoload
$ composer test
- POST /products
- GET /products/[id]
- POST /bundles
- GET /bundles/[id]
- GET /bundles/[id]/products
- POST /orders
- GET /orders/[id]
- GET /orders/[id]/products
- GET /orders/[id]/bundles
- POST /roles
- GET /roles/[id]
- GET /users/[id]
- GET /users/[id]/roles
- POST /users/[id]/roles/[id]
- POST /auth/register
- POST /auth/login
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]
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
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]
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
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
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]
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
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
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
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]
Example: http://localhost:8080/roles/[id]
Request headers: - Authorization: Bearer <jwt_token>
Response body:
{
"id": "1",
"role": "admin"
}
Response status: - Success: 200 - Error: 400
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
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
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
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
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]
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