Register API
A third party service (device driver or support service) might need to expose API endpoints via the ECP Core Services.
The service can register with the Core API Service to have all API request for which the URI starts with a specific prefix redirect to the service itself. The service is then responsible to processing and publishing a response.
Register API endpoints
User: api-user
This requires ase-core-api v0.0.35 or higher.
See the Use API section for background information.
API requests using the AMQP connections use href and requestMethod headers with the request body being the body of the REST request.
The third party service is responsible for registering an 'href
prefix' starting with "support/< identifier >/"
for a support service, or "drivers/< identifier >/" for a
device driver, (the prefix has to be unique within the system) and a
'routing key'
, which is the name of the queue the third party
service has created (see "Incoming API requests"), with the API service for all API
requests that need to be routed to the support service.
The third party service is then responsible for parsing the incoming AMQP message's "href" header and to process the message before sending the result to the replyTo queue.
For example, a potential new support service uses API endpoints all starting with "support/foobar/" and has created a queue "ase.queue.support-foobar-a8few9gjhb-876542" (see Incoming API Requests section below) for incoming API requests.
To register this with the API service an AMQP message should be sent to the
ase.exchange.api
exchange as follows (do not use a replyTo for
this message):
Exchange | Headers | Body |
---|---|---|
ase.exchange.api |
messageType=registerAPI |
{"hrefPrefix":"support/foobar/",
"routingKey":"ase.queue.support-foobar-a8few9gjhb-876542"} |
This should be done when the support service starts up and when a request comes via
the queue bound to the ase.exchange.driver
exchange. The incoming
request just has one header, and no body:
"messageType=requestAPIregistration"
.
Once registered all API requests with an href
header starting with
the prefix will be routed to the registered queue.
Incoming API Requests
User: support-user
This user is allowed to create queues with the ase.queue.support-
prefix, consume messages from these ase.queue.support-
prefixed
queues and publish to amq.gen-
prefixed queues (incoming messages
on ase.queue.support.
will use a replyTo of
"amq.gen-"
).
A third party service (device driver or support service) can use this mechanism to create a queue for incoming API requests.
- Create a unique queue with the the
ase.queue.support-
prefix and a random (alphanumeric) suffix - Consume incoming API request messages
- Publish the result on the
amq.gen-
prefixed queue which was specified as the replyTo queue