Skip to content

lpww/nerdate

Repository files navigation

nerdate API

An API for interacting with nerdate. Written in Go.

API Routes

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

Prerequisites

  1. go
  2. make
  3. golang-migrate
  4. docker
  5. docker-compose

Env Vars

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

Quick Start

  1. make db/up: run the db
  2. make db/migrations/up: run up migrations
  3. make audit: run code quality checks
  4. make run/api: run the server

Important Commands

  • make help: list the available make commands
  • make db/up: run the db in a docker container
  • make db/down: stop the db
  • make db/migrations/up: run up migrations
  • make run/api: run the server

CLI Flags

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

Folder structure

  • 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.

Router

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.

Example requests

GET /v1/healthcheck

curl -i localhost:4000/v1/healthcheck

POST /v1/users

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

GET /v1/users/discover

curl -i localhost:4000/v1/users/discover

POST /v1/swipes

export BODY='{"swiped_user_id":"eab9be97-fb18-449b-b568-5c37b89bff18","liked": true}'
curl -i -d $BODY localhost:4000/v1/swipes

About

A dating API for nerds

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published