An API for interacting with nerdate. Written in Go.
Implemented | Method | URL Pattern | Handler | Action |
---|---|---|---|---|
✅ | GET | /v1/healthcheck | healthcheckHandler | Show application info |
✅ | POST | /v1/users | registerUserHandler | Register a new user |
✅ | GET | /v1/users/discover | discoverUsersHandler | Show available users |
✅ | POST | /v1/swipes | createSwipeHandler | Create a new swipe |
❌ | GET | /v1/users/matches | showMatchesHandler | Show matches |
The .example.env
file lists the variables that that application requires. Move them to .env
and populate the values, they will be automatically loaded by make
before running commands.
cp .example.env .env
make db/up
: run the dbmake db/migrations/up
: run up migrationsmake audit
: run code quality checksmake run/api
: run the server
make help
: list the available make commandsmake db/up
: run the db in a docker containermake db/down
: stop the dbmake db/migrations/up
: run up migrationsmake run/api
: run the server
Flag | Description | Default |
---|---|---|
-port= | Set the port that the server will listen on | 4000 |
-env= | Set the environment (development | staging |
-db-dsn= | Set the PostgreSQL DSN | "" |
-db-max-open-conns= | Set the PostgreSQL max open connections | 25 |
-db-max-idle-conns= | Set the PostgreSQL max idle connections | 25 |
-db-max-idle-time= | Set the PostgreSQL max idle time (ms) | 15*time.Minute |
-limiter-rps= | Set the rate limiter max requests per second | 2 |
-limiter-burst= | Set the rate limiter max burst | 4 |
-limiter-enabled= | Enable the rate limiter | true |
bin
: Contains compiled application binaries, ready for deployment.cmd/api
: Contains application specific code for the nerdate API. Any code for running the server, handling http requests, and handling authentication.internal
: Contains various ancillary packages used by the API. Any code which isn't application specific and can potentially be reused.migrations
: Contains SQL migration files for the DB.remote
: Contains config files and setup scripts for the production server.go.mod
: Will declare project dependencies, versions, and module path.Makefile
: Contains recipes for automating common admin tasks.database
: Contains an init file for the database. Used for installing extensions.
This project uses httprouter. It is a good option for public APIs because it allows custom JSON responses when automatically hanlding 404 and 405 responses. It also automatically handles OPTIONS requests.
curl -i localhost:4000/v1/healthcheck
export BODY='{"name": "lpww", "gender": "male", "dob": "2006-01-02T15:04:05Z", "ascii_art": "image here", "description": "test description", "email": "[email protected]", "password": "abcd1234"}'
curl -i -d $BODY localhost:4000/v1/users
curl -i localhost:4000/v1/users/discover
export BODY='{"swiped_user_id":"eab9be97-fb18-449b-b568-5c37b89bff18","liked": true}'
curl -i -d $BODY localhost:4000/v1/swipes