This directory contains the all files for the Golang Microservice built with Redis.
This project uses Go as it's main language. The version of Go used in this project is 1.22. You can install Go either directly from the Golang website or using goenv.
Redis is used in the project as the primary database. This can be installed either by following instructions for your operating system, or by using Docker.
First create a new directory using your terminal with the command
mkdir go_micro_service
Move to the new directory with the command
cd go_micro_service
Then enter
go mod init go_micro_service
# this command installs all the required dependencies for your project.
go mod tidy
You will be ready to go with your project and start modifying it the way you want.
curl -sS 127.0.0.1:3000/orders | jq
- Select
GET
in the method. - Enter
http://127.0.0.1:3000/orders/
in the URL field. - Click the "Send" button to send the request.
curl -X POST -d '{"customer_id":"'$(uuidgen)'","line_items":[{"item_id":"'$(uuidgen)'","quantity":<<5>>,"price":<<2500>>}]}' 127.0.0.1:3000/orders
- Select
POST
from the dropdown menu for the HTTP method. - Enter
http://127.0.0.1:3000/orders
in the URL field. - Switch to the
Body
tab. - Select JSON as the body type.
Since Httpie/Postman/Thunder Client doesn't directly support shell command execution like uuidgen
, you need to manually generate UUIDs or use an online UUID generator to create them.
This can apply to Postman and Httpie.
- Once you have the UUIDs, you can format the JSON data like this:
{
"customer_id": "generated-uuid-1",
"line_items": [
{
"item_id": "generated-uuid-2",
"quantity": 5,
"price": 2500
}
]
}
- After entering the JSON data, click the "Send" button to send the request.
curl -sS 127.0.0.1:3000/orders/<<enter-order-id>> | jq
- Select
GET
from the dropdown menu for the HTTP method. - Enter
http://127.0.0.1:3000/orders/<<enter-order-id>>
in the URL field. - Click "Send" to execute the request.
curl -X PUT -d '{"status":"shipped"}' -sS "127.0.0.1:3000/orders/<<enter-order-id>>" -v
- Select
PUT
from the dropdown menu for the HTTP method. - Enter
http://127.0.0.1:3000/orders/<<enter-order-id>>
in the URL field. - Add
Content-Type: application/json
if required by your API. - Switch to the "Body" tab.
- Select JSON as the body type.
- Enter the JSON data for the request body:
{
"status": "shipped"
}
- After entering the JSON data, click the "Send" button to send the request.
curl -X PUT -d '{"status":"completed"}' -sS "127.0.0.1:3000/orders/<<enter-order-id>>" -v
- Select
PUT
from the dropdown menu for the HTTP method. - Enter
http://127.0.0.1:3000/orders/<<enter-order-id>>
in the URL field. - Add
Content-Type: application/json
if required by your API. - Switch to the "Body" tab.
- Select JSON as the body type.
- Enter the JSON data for the request body:
{
"status": "completed"
}
- After entering the JSON data, click the "Send" button to send the request.
curl -X DELETE 127.0.0.1:3000/orders/<<enter-order-id>>
- Select
DELETE
from the dropdown menu for the HTTP method. - Enter
http://127.0.0.1:3000/orders/<<enter-order-id>>
in the URL field. - Click "Send" to execute the request.
This is the documentation of the API commands from a microservices course by Dreams Of Code on YouTube by Net Ninja.
Here is the playlist to the full course.
This is the link to the GitHub repo of this course for more info.