Example of REST API with Slim PHP micro framework.
This simple RESTful API made in Slim version 3, allows CRUD operations to manage entities like: Users, Tasks and Notes :-)
Get information about API.
Get help about this api.
Endpoint:
Method: GET
Type:
URL: {{domain-api-rest-slimphp}}
Responses:
Status: Get Help | Code: 200
{
"code": 200,
"status": "success",
"message": {
"endpoints": {
"tasks": "http://localhost:8080/api/v1/tasks",
"users": "http://localhost:8080/api/v1/users",
"notes": "http://localhost:8080/api/v1/notes",
"status": "http://localhost:8080/status",
"this help": "http://localhost:8080"
},
"version": "0.22.2",
"timestamp": 1560897542
}
}
Get status of this api.
Endpoint:
Method: GET
Type:
URL: {{domain-api-rest-slimphp}}/status
Responses:
Status: Get Status | Code: 200
{
"code": 200,
"status": "success",
"message": {
"db": {
"users": 9,
"tasks": 10,
"notes": 5
},
"version": "0.22.2",
"timestamp": 1560897579
}
}
Login and get a JWT Token Authorization Bearer to use this api.
Endpoint:
Method: POST
Type: RAW
URL: {{domain-api-rest-slimphp}}/login
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json |
Body:
{
"email": "super.email@host.com",
"password": "OnePass1"
}
Responses:
Status: Login Failed | Code: 400
{
"message": "Login failed: Email or password incorrect.",
"class": "UserException",
"status": "error",
"code": 400
}
Status: Login OK | Code: 200
{
"code": 200,
"status": "success",
"message": {
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMSIsImVtYWlsIjoibUBiLmNvbS5hciIsIm5hbWUiOiJNTkIiLCJpYXQiOjE1NTg1NTMwNTIsImV4cCI6MTU1OTE1Nzg1Mn0.OQyICWlGW0oSUB-ANrYL2OJTdC2v0OQQO3RQQ3W_KLo"
}
}
Manage Notes.
Endpoint:
Method: GET
Type:
URL: {{domain-api-rest-slimphp}}/api/v1/notes
Endpoint:
Method: GET
Type:
URL: {{domain-api-rest-slimphp}}/api/v1/notes/3
Endpoint:
Method: GET
Type:
URL: {{domain-api-rest-slimphp}}/api/v1/notes/search/my
Endpoint:
Method: POST
Type: RAW
URL: {{domain-api-rest-slimphp}}/api/v1/notes
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json |
Body:
{
"name": "New Soccer Note",
"description": "Magic Goal..."
}
Endpoint:
Method: PUT
Type: RAW
URL: {{domain-api-rest-slimphp}}/api/v1/notes/4
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json |
Body:
{
"name": "My Note Number 4",
"description": "Free Note"
}
Endpoint:
Method: DELETE
Type: FORMDATA
URL: {{domain-api-rest-slimphp}}/api/v1/notes/27
Manage Tasks.
Get all tasks of a user.
Endpoint:
Method: GET
Type:
URL: {{domain-api-rest-slimphp}}/api/v1/tasks
Headers:
Key | Value | Description |
---|---|---|
Authorization | {{jwt}} |
Get one task of a user.
Endpoint:
Method: GET
Type:
URL: {{domain-api-rest-slimphp}}/api/v1/tasks/7
Headers:
Key | Value | Description |
---|---|---|
Authorization | {{jwt}} |
Search tasks of a user.
Endpoint:
Method: GET
Type:
URL: {{domain-api-rest-slimphp}}/api/v1/tasks/search/sleep
Headers:
Key | Value | Description |
---|---|---|
Authorization | {{jwt}} |
Create a task.
Endpoint:
Method: POST
Type: RAW
URL: {{domain-api-rest-slimphp}}/api/v1/tasks
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json | |
Authorization | {{jwt}} |
Body:
{
"name": "Go To Sleep",
"description": "It's too late, go to sleep man ;-)",
"status": 0
}
Update a task of a user.
Endpoint:
Method: PUT
Type: RAW
URL: {{domain-api-rest-slimphp}}/api/v1/tasks/29
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json | |
Authorization | {{jwt}} |
Body:
{
"name": "Go To Sleep NOW!!",
"description": "It's too late, go to sleep man haha...",
"status": 1
}
Delete a task of a user.
Endpoint:
Method: DELETE
Type: FORMDATA
URL: {{domain-api-rest-slimphp}}/api/v1/tasks/29
Headers:
Key | Value | Description |
---|---|---|
Authorization | {{jwt}} |
Manage Users.
Endpoint:
Method: GET
Type:
URL: {{domain-api-rest-slimphp}}/api/v1/users
Headers:
Key | Value | Description |
---|---|---|
Authorization | {{jwt}} |
Endpoint:
Method: GET
Type:
URL: {{domain-api-rest-slimphp}}/api/v1/users/8
Headers:
Key | Value | Description |
---|---|---|
Authorization | {{jwt}} |
Endpoint:
Method: GET
Type:
URL: {{domain-api-rest-slimphp}}/api/v1/users/search/d
Headers:
Key | Value | Description |
---|---|---|
Authorization | {{jwt}} |
Register a new user.
Endpoint:
Method: POST
Type: RAW
URL: {{domain-api-rest-slimphp}}/api/v1/users
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json |
Body:
{
"name": "John User",
"email": "super.email@host.com",
"password": "OnePass1"
}
Update a user.
Endpoint:
Method: PUT
Type: RAW
URL: {{domain-api-rest-slimphp}}/api/v1/users/4
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json | |
Authorization | {{jwt}} |
Body:
{
"name": "Jhon R",
"email": "ram@hotmail.com"
}
Delete a user.
Endpoint:
Method: DELETE
Type: FORMDATA
URL: {{domain-api-rest-slimphp}}/api/v1/users/112
Headers:
Key | Value | Description |
---|---|---|
Authorization | {{jwt}} |
Made with ♥ by thedevsaddam | Generated at: 2019-06-18 19:55:31 by docgen