agile-learning-institute / mentorHub-person-api

GoLang Person API
Apache License 2.0
2 stars 3 forks source link

institute-person-api

Overview

This is a simple GoLang API that provides Get/Post/Patch services for docuements in the People collection. This API uses data from a backing Mongo Database, and supports a VueJS Single Page Appliaction.

The OpenAPI specifications for the api can be found in the docs folder, and are served here

Prerequisits

Optional

Install Go Dependencies

make install

Run Unit Testing

make test

Run the API locally

make local

Serves up the API locally with a backing mongodb database, use ctrl-c to exit

Build the API Container

make container

This will build the new container, and start the mongodb and API container ready for testing. The test script ./test/test.sh is also run so you should see information about an inserted document. You will get a failed. Received HTTP code 000 message if there are problems

Test with StepCI

make stepci

This will run the stepci tests, and expectes to find the API with backing test data at localhost:8082. If you need to start the database and api before running the test you can use

make blackbox

Generate Test Data

make testdata

Generattes loads of test data, ctrl-c to exit

API Testing with CURL

If you want to do more manual testing, here are the curl commands to use

Test Health Endpoint

This endpoint supports the promethius monitoring standards for a healthcheck endpoint

curl http://localhost:8082/api/health/

Test Config Endpoint

curl http://localhost:8082/api/config/

Get Enumerators

curl http://localhost:8082/api/enums/

Get Partner Names

curl http://localhost:8082/api/partners/

Get Mentor Names

curl http://localhost:8082/api/mentors/

Test find all people with IDs

curl http://localhost:8082/api/person/

Test get a person

curl http://localhost:8082/api/person/aaaa00000000000000000000

Test add a person

curl -X POST http://localhost:8082/api/person/ \
     -d '{"userName":"Foo", "description":"Some short description"}'

Test update a person

curl -X PATCH http://localhost:8082/api/person/aaaa00000000000000000021 \
     -d '{"description":"Some long description"}'

Observability and Configuration

The api/config/ endpoint will return a list of configuration values. These values are either "defaults" or loaded from an Environment Variable, or found in a singleton configuration file of the same name. Configuration files take precidence over environment variables. The variable "CONFIG_FOLDER" will change the location of configuration files from the default of ./

The api/health/ endpoint is a Promethius Healthcheck endpoint.

The Dockerfile uses a 2-stage build, and supports both amd64 and arm64 architectures. See docker-build.sh for details about how to build in the local architecture for testing, and [docker-push.sh] for details about how to build and push multi-architecture images.