Skip to main content

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

  1. status - response status
  1. results - Total records
  1. modules - Array api modules and their routes
  1. data - Array containing all roles
  1. 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

  1. name - Role name

Request

POST
http://localhost:5501/api/v1/role/

Response

{
"status": "String",
"message": "String"
}

Response Validation

  1. status - request status
  1. 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

  1. id - Role ID
  1. model - api module and its route
  1. 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

  1. status - request status
  1. 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

  1. name - Role name
  1. id - Role ID

Request

DELETE
http://localhost:5501/api/v1/role/