Skip to content

colebaileygit/basic-api-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic API Server

Quick Start

  1. set your Google Maps API key via:

    export GOOGLE_API_KEY="<INSERT KEY HERE>"
  2. Run unit + integration tests and then run service

    sh start.sh
  3. Wait for app / db initialization. During start-up, app will wait for up to 30s for DB to be initialized.

  4. Query service at localhost:8080 e.g.

    curl -L -X GET \
    'http://localhost:8080/orders?page=0&limit=3' \
    -H 'Content-Type: application/json'

Running API service

From Docker Compose

Recommended for automatic management of database, build-args, ports, etc.

docker-compose up --build app

From Docker

docker build ./app -t basic-api --build-arg GOOGLE_API_KEY=$GOOGLE_API_KEY --build-arg PORT=8080
docker run --rm -p 8080:8080 basic-api

From Local Environment

go get
go run main.go

Database Migrations

Migration are run automatically to latest version on app start.

To reset / drop database for testing on a clean slate, run

docker-compose down --volumes

Testing

Automated Tests

Integration + Unit Tests

docker-compose up tester

Unit Tests

docker-compose run tester go test ./... -short

Alternative, for quicker debugging if local environment is configured:

cd app
go test ./... -short

Manual Tests

First, make sure your service is running using instructions above.

Create Order

curl -L -X POST \
  http://localhost:8080/orders \
  -H 'Content-Type: application/json' \
  -d '{"origin": ["22.278", "114.185"], "destination": ["22.31", "114.212"]}'

Take Order

curl -L -X PATCH \
  http://localhost:8080/orders/2 \
  -H 'Content-Type: application/json' \
  -d '{"status": "TAKEN"}'

Fetch Orders

curl -L -X GET \
  'http://localhost:8080/orders?page=0&limit=3' \
  -H 'Content-Type: application/json'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published