Skip to content

Commit d53e841

Browse files
authored
Update README.md
1 parent 3cec557 commit d53e841

File tree

1 file changed

+62
-56
lines changed

1 file changed

+62
-56
lines changed

README.md

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
# golang-test-api
2-
1+
- # golang-test-api
32
A simple CRUD API made with Go, Postgres, FIber, Gorm and Docker.
43

54
- ## Cloning the repository
65
To clone the repository run the following command:
7-
```
6+
```bash
87
$ git clone https://github.com/WeDias/golang-test-api.git
98
```
109

1110
- ## How to install and run (docker)
12-
Inside the newly cloned project folder run the following command:
13-
```
14-
$ docker compose up
15-
```
11+
Inside the newly cloned project folder run the following command:
12+
```bash
13+
$ docker compose up
14+
# or
15+
$ docker-compose up
16+
```
1617

1718
- ## How to install and run (manually)
1819

1920
- ### Installing the dependencies and setup env
2021
Inside the newly cloned project folder run the following command to install the dependencies:
21-
```
22+
```bash
2223
$ go mod download
2324
```
2425
To configure the environment run this command:
25-
```
26+
```bash
2627
$ bash setup-env.sh
2728
```
2829
It will generate a .env file with the variables below, you can edit to adapt with your database settings.
29-
```
30+
```bash
3031
PG_HOST=localhost
3132
PG_PASS=postgres
3233
PG_USER=postgres
@@ -39,64 +40,69 @@
3940

4041
- ### Running the application
4142
Inside the project, run the following command to run the application:
42-
```
43+
```bash
4344
$ go run main.go
4445
```
4546

4647
- ## API
48+
#### Create a new product:
49+
```bash
50+
# POST /api/v1/product
51+
52+
$ curl --request POST \
53+
--url http://localhost:3000/api/v1/product \
54+
--header 'Content-Type: application/json' \
55+
--data '{
56+
"name": "product1",
57+
"price": 10.99,
58+
"stock": 10
59+
}'
60+
61+
> {"id":1,"name":"product1","price":10.99,"stock":10}
4762
```
48-
# POST /api/v1/product
49-
50-
$ curl --request POST \
51-
--url http://localhost:3000/api/v1/product \
52-
--header 'Content-Type: application/json' \
53-
--data '{
54-
"name": "product1",
55-
"price": 10.99,
56-
"stock": 10
57-
}'
5863

59-
> {"id":1,"name":"product1","price":10.99,"stock":10}
60-
```
64+
#### Get all products:
65+
```bash
66+
# GET /api/v1/product
6167

62-
```
63-
# GET /api/v1/product
68+
$ curl --request GET \
69+
--url http://localhost:3000/api/v1/product
6470

65-
$ curl --request GET \
66-
--url http://localhost:3000/api/v1/product
67-
68-
> [{"id":1,"name":"product1","price":10.99,"stock":10}]
69-
```
70-
71-
```
72-
# GET /api/v1/product/1
73-
74-
$ curl --request GET \
75-
--url http://localhost:3000/api/v1/product/1
76-
77-
> {"id":1,"name":"product1","price":10.99,"stock":10}
78-
```
71+
> [{"id":1,"name":"product1","price":10.99,"stock":10}]
72+
```
7973

80-
```
81-
# PUT /api/v1/product/1
74+
#### Get a product by id:
75+
```bash
76+
# GET /api/v1/product/1
8277

83-
$ curl --request PUT \
84-
--url http://localhost:3000/api/v1/product/1 \
85-
--header 'Content-Type: application/json' \
86-
--data '{
87-
"name": "a product",
88-
"price": 8.99,
89-
"stock": 5
90-
}'
78+
$ curl --request GET \
79+
--url http://localhost:3000/api/v1/product/1
9180

92-
> {"id":1,"name":"a product","price":8.99,"stock":5}
93-
```
81+
> {"id":1,"name":"product1","price":10.99,"stock":10}
82+
```
83+
84+
#### Update a product by id:
85+
```bash
86+
# PUT /api/v1/product/1
87+
88+
$ curl --request PUT \
89+
--url http://localhost:3000/api/v1/product/1 \
90+
--header 'Content-Type: application/json' \
91+
--data '{
92+
"name": "a product",
93+
"price": 8.99,
94+
"stock": 5
95+
}'
96+
97+
> {"id":1,"name":"a product","price":8.99,"stock":5}
98+
```
9499

95-
```
96-
# DELETE /api/v1/product/1
100+
#### Delete a product by id:
101+
```bash
102+
# DELETE /api/v1/product/1
97103

98-
$ curl --request DELETE \
99-
--url http://localhost:3000/api/v1/product/1
104+
$ curl --request DELETE \
105+
--url http://localhost:3000/api/v1/product/1
100106

101-
> {"id":1,"name":"a product","price":8.99,"stock":5}
107+
> {"id":1,"name":"a product","price":8.99,"stock":5}
102108
```

0 commit comments

Comments
 (0)