HTTP to NATS Proxy Service written in Rust. Useful as the entrypoint to NATS-based microservices to provide REST APIs externally.
The HTTP method and url path are used to create the NATS subject. The first part is the method, and the rest are each of the path segments.
For example, GET /animals/dog
becomes get.animals.dog
.
JSON in the following format:
{
originReplyTo: String,
headers: Map<String, String>,
body: Value,
}
originReplyTo
- NATS inbox reply subject.headers
- HTTP headers sent in request.body
- Request body.
Example:
{
"originReplyTo": "_INBOX.eA3HitirD384mypcqrLgDS",
"headers": {
"Content-Type": "application/json",
"Host": "example.com"
},
"body": {
"color": "blue"
}
}
JSON in the following format:
{
headers: Map<String, String>,
body: Value,
statusCode: integer,
}
headers
- HTTP response headers.body
- response body.statusCode
- HTTP response status code.
Example:
{
"headers": {
"Content-Type": "application/json",
"Content-Encoding": "br"
},
"body": {
"color": "blue"
},
"statusCode": 200
}
The service reads the folowing environment variables on startup:
NATS_SERVICE_HOST
- NATS server url host e.g. 10.0.0.11NATS_SERVICE_PORT
- NATS server url port e.g. 4222
Using the above example values, the service will try to connect to the NATS
server at nats://10.0.0.11:4222
.
To run ther service:
cargo run