/django_service_registry

A service registry with a REST interface implemented in Django

Primary LanguagePython

A Service Registry using Django

Overview

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.

Installation

- Ensure that you are running in a Python3 environment.
- pip install -r requirements.txt

Running the Django development server

$ python manage.py runserver

URL format

All endpoints are prefixed by /services/<api_version_number>. For example to find information about a service:

GET /services/v1/<name>

Testing

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.

Add a service

$ 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" 
}

Find a service

$ curl -i http://localhost:8000/services/v1/test1

Returns: (if we have added test1 twice)

{
  "service":"test1",
  "count":2
}

Delete a service

$ curl -i -H "Content-Type: application/json" -X DELETE http://localhost:8000/services/v1/test1

Returns:

{
  "change":"removed",
  "service":"test1"
}

Update a service

$ 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"
}

List all registered services (N.B. not in the reqs. for development only)

$ 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"
  }
]

TODO

- 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