it's a jwt authorization implementation. Here's a API flow task details:
Buatlah Rest API product (create, read, update, delete) dengan fitur login dan register, serta memiliki 3 fitur middleware antara lain :
- Authentication
- Authorization multi level user
- Authorization access product by id
Notes : buatlah authentication dengan JWT token golang, lalu gunakan token tersebut untuk setiap hit Rest API product.
it's a register user endpoint. This endpoint can be accessed by everyone.
Request Body :
{
"fullname" : "string",
"email" : "string", # must be a valid email
"password" : "string",
"role" : "string" #must be a valid role, but omitempty
}
Notes : On this endpoint, password
will be hashed using crypto
library
Response Body :
it's a login user endpoint. This endpoint can be accessed by everyone.
Request Body :
{
"email" : "string", # must be a valid email
"password" : "string",
}
Response Body :
it's a create product endpoint. This endpoint only can be accessed by admin
and user
.
Request Headers
Authorization : Bearer <token>
Request Body :
{
"title" : "string",
"description" : "string",
}
Response Body :
it's a update product endpoint. This endpoint only can be accessed by admin
.
Params
- productId :
int
| required
Request Headers
Authorization : Bearer <token>
Request Body :
{
"title" : "string",
"description" : "string",
}
Response Body :
it's a delete product endpoint. This endpoint only can be accessed by admin
.
Params
- productId :
int
| required
Request Headers
Authorization : Bearer <token>
Response Body :
it's a get all product {by userId jwt} endpoint. This endpoint only can be accessed by admin
and user
.
Request Headers
Authorization : Bearer <token>
Response Body :
it's a get product by productId endpoint. This endpoint only can be accessed by admin
and user
.
Params
- productId :
int
| required
Request Headers
Authorization : Bearer <token>
Response Body :