janus

package module
v0.0.0-...-f984256 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2017 License: MIT Imports: 0 Imported by: 0

README

Janus

GoDoc Go Report Card

An Api Gateway written in Go

This is a lightweight, API Gateway and Management Platform enables you to control who accesses your API, when they access it and how they access it. API Gateway will also record detailed analytics on how your users are interacting with your API and when things go wrong.

Why Janus?

In ancient Roman religion and myth, Janus (/ˈdʒeɪnəs/; Latin: Ianus, pronounced [ˈjaː.nus]) is the god of beginnings, gates, transitions, time, doorways, passages, and endings. He is usually depicted as having two faces, since he looks to the future and to the past. Wikipedia

We thought it would be nice to name the project after the God of the Gates 😄

What is an API Gateway?

An API Gateway sits in front of your application(s) and/or services and manages the heavy lifting of authorisation, access control and throughput limiting to your services. Ideally, it should mean that you can focus on creating services instead of implementing management infrastructure. For example if you have written a really awesome web service that provides geolocation data for all the cats in NYC, and you want to make it public, integrating an API gateway is a faster, more secure route that writing your own authorisation middleware.

Key Features

This API Gateway offers powerful, yet lightweight features that allow fine gained control over your API ecosystem.

  • No dependency hell - Single binary made with go
  • REST API - Full programatic access to the internals makes it easy to manage your API users, keys and Api Configuration from within your systems
  • Rate Limiting - Easily rate limit your API users, rate limiting is granular and can be applied on a per-key basis
  • CORS Filter - Enable cors for your API,or even for specific endpoints
  • API Versioning - API Versions can be easily set and deprecated at a specific time and date
  • Multiple auth protocols - Out of the box, we support JWT, OAtuh2 and Basic Auth access methods
  • Hot-reloading of configuration - No need to restart the process
  • Graceful shutdown - Graceful shutdown of http connections
  • Docker Image - Small official docker image included

Installation

Docker

The simplest way of installing janus is to run the docker image for it. Just check the docker-compose.yml example and then run.

docker-compose up -d

Now you should be able to get a response from the gateway, try the following command:

curl http://localhost:8080/
Manual

You can get the binary and play with it in your own enviroment (or even deploy it whereever you like it). Just go the releases and download the latest one for your platform.

Make sure you have the following dependencies installed in your enviroment:

  • Mongodb - For storing the proxies configurations
  • Redis - For caching and storing of expiration oauth tokens

And then just define where your dependencies are located

export DATABASE_DSN="mongodb://localhost:27017/janus"
export REDIS_DSN="redis://localhost:6379"
export SECRET="yourSecret"
export ADMIN_USERNAME="admin"
export ADMIN_PASSWORD="admin"

If you want you can have a stastd server so you can have some metrics about your gateway. For that just define:

export STATSD_DSN="statsd:8125"
export STATSD_PREFIX="janus."

Getting Started

After you have janus up and running we need to setup our first proxy. Everything that we want to do on the gateway we do it through a REST API, since all endpoints are protected we need to login first.

http -v --json POST localhost:3000/login username=admin password=admin

The username and password are defined in a enviroment variable called ADMIN_USERNAME and ADMIN_PASSWORD, it defaults to admin/admin.

Creating a proxy

The main feature of the API Gateway is to proxy the requests to a different service, so lets do this. Now that you are authenticate you can send a request to /apis to create a proxy.

http -v --json POST localhost:3000/apis "Authorization:Bearer yourToken" "Content-Type: application/json" < examples/api.json

This will create a proxy to https://jsonplaceholder.typicode.com/posts when you hit the api gateway on GET /posts. Now just make a request to GET /posts

http -v --json GET http://localhost:3000/posts/1

Done! You just made your first request through the gateway.

Contributing

To start contributing, please check CONTRIBUTING.

Documentation

Documentation

Overview

Package janus is a lightweight, API Gateway and Management Platform enables you to control who accesses your API, when they access it and how they access it. API Gateway will also record detailed analytics on how your users are interacting with your API and when things go wrong.

For a full guide visit https://github.com/hellofresh/janus

Directories

Path Synopsis
cmd
pkg
api
Package api holds the models for the API Definition.
Package api holds the models for the API Definition.
config
Package config provides the configuration for Janus.
Package config provides the configuration for Janus.
cors
Package cors provides a default struct to hold the cors configuration and also a http middleware.
Package cors provides a default struct to hold the cors configuration and also a http middleware.
errors
Package errors provides a nice way of handling http errors Examples: To create an error: err := errors.New(http.StatusBadRequest, "Something went wrong")
Package errors provides a nice way of handling http errors Examples: To create an error: err := errors.New(http.StatusBadRequest, "Something went wrong")
jwt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL