A solution using Django and the Django REST Framework to demo the Service Registry API. This Service Registry API provides endpoints for creating, finding, deleting, and updating services in the registry.
- Ensure that you are running in a Python3 environment.
- pip install -r requirements.txt
$ python manage.py runserver
All endpoints are prefixed by /services/<api_version_number>. For example to find information about a service:
GET /services/v1/<name>
Django REST framework allows the API to be browsed. Simply point your browser at http://127.0.0.1:8000/services/v1 to get started.
There are unit and BDD tests that can be run as shown below:
$ python manage.py test
$ python manage.py behave
In addition, you can test the API from the command line using cURL. This allows you to easily investigate and test the service as shown in the examples below.
$ curl -i -H "Content-Type: application/json" -X POST -d '{"service":"test1","version":"0.0.1"}' http://localhost:8000/services/v1
Returns:
{
"service": "test1",
"version": "0.0.1",
"change": "created"
}
$ curl -i http://localhost:8000/services/v1/test1
Returns: (if we have added test1 twice)
{
"service":"test1",
"count":2
}
$ curl -i -H "Content-Type: application/json" -X DELETE http://localhost:8000/services/v1/test1
Returns:
{
"change":"removed",
"service":"test1"
}
$ curl -i -H "Content-Type: application/json" -X PUT -d '{"service":"test99","version":"1.1.1"}' http://localhost:8000/services/v1/1
Returns:
{
"change":"changed"
}
$ curl -i http://localhost:8000/services/v1
Returns:
[
{
"service":"updatetest",
"version":"9.0.1"
},
{
"service":"test",
"version":"0.0.1"
},
{
"service":"test",
"version":"0.0.1"
}
]
- Improve tests
- Improve input validation and error handling
- Add logging
- Add authentication and authorisation
- Run over TLS
- Improve commenting
- Add some mechanism for reporting and checking health of services
- Add additional fields such as the URL of the service
- Add rate limiting
- Remove unnecessary modules from requirements.txt
- Update validators