Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.
/ apidCounters Public archive

Example plugin for apid documenting patterns for using and testing services

License

Notifications You must be signed in to change notification settings

apid/apidCounters

Repository files navigation

apidCounters

Build Status GoDoc Go Report Card

This is an EXAMPLE plugin for apid. It shows how to register as a plugin and use apid's API, Config, Data, Events, and Log Services. In addition, it shows how to write integration tests that use these services. This is not necessary intended to be a production-ready apid component.

Functional description

This plugin simply tracks counters based on called URIs:

  • GET /counters - retrieve all counters
  • GET /counters/{name} - retrieve named counter
  • POST /counters/{name} - increment named counter (returns prior value)

Apid Services Used

  • Config Service
  • Log Service
  • API Service
  • Event Service: to publish counter increment events
  • Data Service: to store counters

Building and running

First, install prerequisites:

glide install

To run an apid test instance with just this plugin installed, change to the cmd/apidExample folder. From here, you may create an executable with:

go build 

Alternatively, you may run without creating an executable with:

go run main.go 

Either way, once the process is running, you should be able to manually give the plugin's API a whirl...

curl -i -X POST localhost:9000/counters/counter1 
curl -i localhost:9000/counters/counter1
curl -i localhost:9000/counters

Note that both port value and the /counters base path have been exposed as configurable. Thus, the following env variables will affect the values used for these, respectively:

  • APID_API_PORT
  • APID_COUNTERS_BASE_PATH

For example, if you set the APID_COUNTERS_BASE_PATH env var to /test, all the paths above will be based at /test instead of /counters.

Running tests

To run the tests, just run:

go test

To generate coverage, you may run:

./cover.sh

Then open cover.html with your browser to see details.

About

Example plugin for apid documenting patterns for using and testing services

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published