First, clone the repository:
git clone [email protected]:parsaakbari1209/crud-echo.git
Next, change the current directory to the repository:
cd crud-echo
Next, install the dependencies:
go get ./...
Finally, run the app on port 8000
:
go run .
GET /users/:email
POST /users
PUT /users/:email
DELETE /users/:email
This endpoint retrieves a user given the email.
Send a GET
request to /users/:email
:
curl -X GET 'http://127.0.0.1:8000/users/[email protected]'
Response:
{
"name": "Bob",
"email": "[email protected]",
"password": "secure"
}
This endpoint creates a user given the information.
Send a POST
request to /users
:
curl -X POST 'http://127.0.0.1:8000/users' -H "Content-Type: application/json" -d '{"name": "Bob", "email": "[email protected]", "password": "secure"}'
Response:
{
"name": "Bob",
"email": "[email protected]",
"password": "secure"
}
This endpoint updates the provided fields for the given user email.
Send a PUT
request to /users/:email
:
curl -X PUT 'http://127.0.0.1:8000/users/[email protected]' -H "Content-Type: application/json" -d '{"password": "secure_v2"}'
Response:
{
"name": "Bob",
"email": "[email protected]",
"password": "secure_v2"
}
This endpoint deletes the user given the email.
Send a DELETE
request to /users/:email
:
curl -X DELETE 'http://127.0.0.1:8000/users/[email protected]'
Response:
{
"name": "Bob",
"email": "[email protected]",
"password": "secure_v2"
}
All of the endpoints return an error in json format with a proper http status code, if something goes wrong:
{
"message": "user not found"
}