Code Monkey home page Code Monkey logo

apigateway's Introduction

apigateway

Test codecov Go Report Card

apigateway is an API gateway designed for use in development environments or sandboxes. It follows these principles in its design:

  • Its configuration is simple.
  • It can be used directly within Docker Compose.
  • It does not perform load balancing.
  • It does not modify requests and responses.
  • It leverages the reverse proxy provided in Go's standard library, ensuring optimal performance and efficiency.

Using with Docker Compose

docker-compose.yml

version: '3'

services:
  apigateway:
    container_name: apigateway
    restart: always
    image: imererman/apigateway:latest
    volumes:
      - ./config.yml:/app/config.yml
    networks:
      - apigateway-network
    ports:
      - 80:8080
    
  service1:
    container_name: service1
    ...
    networks:
      - apigateway-network

networks:
  apigateway-network:
    name: apigateway-network

config.yml

upstreams:
  - pattern: /service1/
    strip_prefix: true
    url: http://service1:8080

With this configuration in docker-compose, all requests starting with the /service1/ pattern coming to the API gateway will be forwarded to service1 after stripping the pattern. For example:

http://localhost:80/service1/health-check -> http://service1/8080/health-check:

If strip_prefix was false, the request coming to the API gateway as above would be forwarded to service1 without stripping the pattern, as follows:

http://localhost:80/service1/health-check -> http://service1/service1/8080/health-check:

Configuration

As seen in the example above, only upstream configuration is sufficient. Below, the default configuration for the server is shown. If desired, the server can also be configured.

server:
  address: :8080
  read_timeout: 5s
  write_timeout: 10s
  idle_timeout: 120s
  max_header_bytes: 1048576 # 1 MB
  shutdown_timeout: 10s

upstreams:
...

Build And Run

To build the project with Go, you can run the following commands in the project directory.

build:

go build ./cmd/apigateway

run:

./apigateway

Note: apigateway always looks for the config.yml file in its directory.

Contribution

Open an issue and let's collectively decide on the changes and features you want. Then, you can proceed by opening a pull request from the main branch of your forked repository to the main branch of the main repository.

License

This repo is under the MIT license.

apigateway's People

Contributors

ermanimer 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.