Roles
API roles
Tip
Ensure you have completed the configuration steps Here
Get all Roles
Request
GET
http://localhost:5501/api/v1/role/
Response
{
"status": "String",
"results": "Number",
"modules": "Array",
"data": "Array",
"userPerRole": "Object",
}
Response Validation
- status - response status
- results - Total records
- modules - Array api modules and their routes
- data - Array containing all roles
- userPerRole - Object containing roles and total users in the role
Example
Response
{
"status": "success",
"results": 2,
"modules": [
{
"model": "apps",
"path": "api/v1/app"
},
{
"model": "auths",
"path": "api/v1/auth"
}
],
"data": [
{
"_id": "629a0ee3f1780010a260ded4",
"name": "USER",
"permissions": [
{
"path": "/roles",
"model": "roles",
"access": []
},
{
"path": "/auths",
"model": "auths",
"access": [
"PATCH",
"GET",
"POST"
]
},
{
"path": "/blogs",
"model": "blogs",
"access": [
"GET"
]
}
],
"__v": 0
}
],
"userPerRole": {
"629a0ee3f1780010a260ded2": {
"name": "ADMIN",
"total": 1
},
"629a0ee3f1780010a260ded4": {
"name": "USER",
"total": 2
}
}
}
Add a new role
Request body
{
"name":"String"
}
Body Validation
- name - Role name
Request
POST
http://localhost:5501/api/v1/role/
Response
{
"status": "String",
"message": "String"
}
Response Validation
- status - request status
- message - response message
Example
Body
{
"name":"files"
}
Response
{
"status": "failed",
"message": "Both the Admin and User role have already been configured."
}
Update Role
Request body
{
"id":"String",
"model":"String",
"access":"Array"
}
Body Validation
- id - Role ID
- model - api module and its route
- access - List of REST api methods allowed for the role
Request
PATCH
http://localhost:5501/api/v1/role/
Response
{
"status": "String",
"data": "Object"
}
Response Validation
- status - request status
- data - response message
Example
Body
{
"id":"629a0ee3f1780010a260ded4",
"model":"roles",
"access":["GET"]
}
Response
{
"status": "success",
"data": "saved"
}
Delete Role
Info
Deleting a Role is currently not supported, but the API route is implemented for future Implementation
Request body
{
"name":"String",
"id":"String"
}
Body Validation
- name - Role name
- id - Role ID
Request
DELETE
http://localhost:5501/api/v1/role/