This project is a simple API that make requests to URLs based on the request body. It can be used to deploy microservices infrastructures containing multiple services that interact with each other or with external APIs. The docker image is published on Docker Hub.
This project leverages the OAS Tools v3 framework to route requests and simplify the development of the API. The API is defined in the Open API Document file and API documentation can be accessed at http://localhost:8080/docs once the API is deployed.
The API can be deployed locally or containerized. The following sections explain how to deploy the API in both ways, and make requests to it.
To deploy the API locally, you need to have Node.js installed. Once you have it, you can clone this repository and run the following command:
> npm start
This will start the API on port 8080. You can change the port by setting the environment variable PORT
to the desired value.
To deploy the API in a container, you need to have Docker installed. Once you have it, you can pull the image from Docker Hub and run it with the following commands:
> docker pull alesancor1/api-requester
> docker run -p 8080:8080 alesancor1/api-requester
You can also deploy a microservice infrastructure using only this API through Docker Compose. The following docker-compose.yml
file shows an example with 3 services:
version: "3.8"
services:
microservice-one:
container_name: microservice-one
image: alesancor1/api-requester
ports:
- "8080:80"
microservice-two:
container_name: microservice-two
image: alesancor1/api-requester
ports:
- "8081:80"
microservice-three:
container_name: microservice-three
image: alesancor1/api-requester
ports:
- "8082:80"
Once the API is deployed, you can make POST requests to it. The request body must be a JSON object with the following structure:
{
"url": "https://example.com",
"method": "GET",
"headers": {
"Content-Type": "application/json"
},
"body": {
"key": "value"
}
}
Additionally, having deployed multiple instances of the API, you can make requests to them from each other. For example, if you have deployed the API on port 8080 and 8081, you can make a request to the second one from the first one with the following body:
[{
"url": "http://localhost:8081/api/v1/request",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": {
"url": "https://example.com",
"method": "GET"
}
},
{
"url": "https://example.com",
"method": "GET"
}]
Note that the above example declares an array instead of an object. When request body is an Array, the API will make a request to each element of the array and return an array with the responses.
This project is licensed under the GNU GPLv3 License - see the LICENSE file for details.