GithubHelp home page GithubHelp logo

alesancor1 / api-requester Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 45 KB

Service that makes requests to an API based on request body

License: GNU General Public License v3.0

Dockerfile 6.43% JavaScript 93.57%

api-requester's Introduction

Generic API Requester

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.

How to use

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.

Local deployment

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.

Containerized deployment

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

Deploying with Docker Compose

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"

Making requests

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.

License

This project is licensed under the GNU GPLv3 License - see the LICENSE file for details.

api-requester's People

Contributors

alesancor1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.