- HTTP Router: https://github.com/go-chi/chi
- CORS checks: https://github.com/go-chi/cors
- Request id generation(KSUID): https://github.com/segmentio/ksuid
- Logging: https://github.com/sirupsen/logrus
To be able to use postgres locally without SSL, comment the following lines of code in db/db.go:
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
},
This disables ssl connection with the postgres instance locally. It is used in the deployed version of the app to ensure communication with the DB is encrypted.
To take a look at the API structure and try out endpoints, go to http://localhost:8080/api/v1/swagger/index.html
There are two options to run the API:
- Make sure you have Postgres running
- Add your env variables(check config/config.go) for db credentials
- Run
make migrate
(this will run migrations and then run the server) - Go to
localhost:8080
to access the API
- Run
docker-compose up
. This will create two containers: one for the Postgres db, and another for the API. - Go to
localhost:8080
to access the API
To run tests, run go test ./controllers ./services
To see the API up and running, visit https://pack-delivery-api.onrender.com/api/v1/products and make a POST request. Make sure you provide the correct request body so that it passes the API validations.
/POST /api/v1/products
Enables the end user to order products defined by the request body. It will return the response as stated below.
{
"amount": int
}
{
"amount_of_packs": int,
"pack_size": int
}