GIN SQLX EXAMPLE
Sample implementation gin
, postges
using sqlx
.
This project will create a database named sampledb
along with a table named Animal
:
sampledb=# SELECT * FROM animals;
id | name | age | description
----+------+-----+-------------
(0 rows)
Prerequisites :
Running :
make environment
- create file
.env
based on .env.sample
make server
- app will running in port 8080!
Note : you can use command
make help
for showing list available commands.
Testing Locally using curl :
- Create animal
curl --location 'http://localhost:8080/animals' \
--header 'Content-Type: application/json' \
--data '{
"name": "cow",
"age": 20,
"description": "beautiful cow"
}'
- List all animal
curl --location 'http://localhost:8080/animals'
- Detail animal
curl --location 'http://localhost:8080/animals/11'
- Update animal
curl --location --request PATCH 'http://localhost:8080/animals/12' \
--header 'Content-Type: application/json' \
--data '{
"name": "cat",
"age": 15,
"description": "beautiful cat update"
}'
- Delete animal
curl --location --request DELETE 'http://localhost:8080/animals/13'