Giter Club home page Giter Club logo

janus's Introduction

##Janus

Janus is a fake rest api server which can be used for various purpose including frontend application development , testing etc.

Features

  • Easy to configure and use.
  • Supports all http methods and REST resources.
  • Supports CORS.
  • Basic Auth Support
  • Available in all platforms.

Install

Get Binary Distribution

You can download the latest binary distribution from here

Build from source

Go should be installed (version 1.4+ is required) in the system. Make sure you have Go properly installed, including setting up your GOPATH.

go get -u github.com/jijeshmohan/janus

How to run

To run janus, go to any directory and create a json file called config.json . This defines the REST endpoints which server need to expose. ( config.json file described in the next section.). Run the application in the same directory by typing janus in the terminal

Note : A sample config and associated files are there in example directory.

Basic Structure of a config.json file

The basic structure of config file shown below. A config file has follwing attributes

  • port
  • enableLog
  • delay
  • auth
  • jwt
  • resources
  • urls
  • static

Detailed description of each attributes are below.

e.g config.json

{
  "port": 8080,
  "enableLog": false,
  "delay": 0,
  "auth": {
    "username": "user1",
    "password": "secret"
  },
  "resources": [
    {
      "name": "user",
      "headers": {
        "key": "value"
      }
    }
  ],
  "urls": [
    {
      "url": "direct/url/for/something",
      "method": "GET",
      "content_type": "application/json",
      "status": 200,
      "file": "./files/some.json",
      "headers": {
        "key": "value",
        "key1": "value1"
      }
    }
  ]
}
Port

port in configuration file defines in which port the server needs to run.This is an optional field and if not provided the default port is 8000.

EnableLog

enableLog in configuration file defines whether we need to log the requests form clients. Default values is false.

Delay

delay in configuration file provides a response delay ( in milliseconds). Default value is 0 which means there is no delay. This feature helps to simulate network delay or server response time.

Auth

auth in configuration provides basic auth support in janus. This is an optional field. If provided this will verify the username and password for all requests.

You need to specify username and password like below

"auth": {
  "username": "user1",
  "password": "password"
}
JWT

jwt in configuration provides jwt support in janus. This will issue a new jwt token when they call the url specified in jwt section below.

"jwt": {
  "url": "/auth/token",
  "exp:" 12, // expiry in minutes 
  "secret": "secret key"
  "data": {
    "userid": 1234,
    "admin": false
  }
}
Static

staic in configuration allows to serve static files in janus. With this option you can make janus to serve static files for your api ( e.g. javascript frontend like angular, reactjs etc..)

"static": {
	"url": "/ui",
	"path": "public"
}

In above configuration, url specifies what would be the root path of your static files , like http://localhost:8080/ui/index.html and path specified the actual directory from which teh static files need to be served. This is relative to the configuration files directory.

REST enspoints

You can define two types of REST endpoints in the configuration file

  • resources
  • urls
Resources

This represent basic REST resource which will exposes all standard methods. Janus will look for a folder with the name of the resource in the same directory as routes.json for sending the data correspoding to the methods.

e.g:

{
	"name": "user"
	"headers": {  // headers field is optional
		"key": "value"
	}
}

e.g for user resource , it wil look follwoing files to send the data

Verb Url FILE Description
GET /user ./user/index.json if the file not available app will send a 404
POST /user ./user/post.json if file is present it will send 201 with the content of the file otherwise 404
GET /user/:item ./user/[any file name which is matching :item].json if the file present, it will send the file with 200, otherwise 404. you can add item1.json, item2.json etc if you want to fake different get request
PUT /user/:item will use the same file specified above if file is present it will send 200 with the content of the file otherwise 404. You can specify any number of files to match the get requst like user1.json, admin.json etc.
PATCH /user/:item will use the same file specified above if file is present it will send 200 with the content of the file otherwise 404.
DELETE /user/:item will use the same file specified above if file is present it will send 200 with the content of the file otherwise 405. If you have specified item1.json, then it will send 200 for that particular item's request.

You can specify any header informations which need to send along with the methods. This is optional field

Urls

Urls section is for specifying individual urls which can't qualify for a standard REST resource methods.

This section gives more freedom in terms for defining HTTP Methods and content type and files.

A single url representasion showed below

 {
   "url": "/admin/user/enable", //mandatory
   "method": "GET", // mandatory
   "content_type": "application/json", // optional. default to application/json; charset=utf-8
   "status": 200, // optional , default to 200
   "file": "./files/some.json" // optional, if not specified , the response will be empty string. if specified it should be a valid file.
   "headers": {  //Optional
    "key": "value",
    "key1": "value1"
   }
}

Note: Url also support dynamic url like /admin/{user}/enable which can match to any user name like /admin/user1/enable or /admin/anotheruser/enable .

TODO

  • File upload support
  • Compression
  • Websocket support.
  • Admin UI for configuration and adding url at runtime.

Changelog

Please check the changelog here

License

The MIT License.

janus's People

Contributors

jijeshmohan avatar maheshbr avatar

Stargazers

Cyan Tarek avatar Cioclea Doru Octavian avatar Athira avatar Josué Rodriguez avatar bill avatar Enrique Bris avatar  avatar Doug Johnson avatar  avatar Eugene Klimov avatar Nicolas Marshall avatar Michael S. Manley avatar Michael Yan avatar Joshua Magady avatar Timo Reimann avatar Ben Burns avatar xiaoping avatar Johnny avatar Justin Lee avatar  avatar Daniel Einspanjer avatar Jim Ma avatar Ben Sooter avatar  avatar Orson Wang avatar Jesaja Everling avatar Zed Zaxter avatar Andrew Kiellor avatar Isa Goksu avatar WojtekZ avatar Jinesh Panampattakunnath avatar Angus H. avatar Adam Patterson avatar David Paluy avatar Evgeniy Vasilev avatar  avatar Zach Badgett avatar Haokang Den avatar Noel avatar Michael Hood avatar Gus Becciu avatar txgo avatar Adam Cianfichi avatar James Mason avatar Andrew Hodges avatar zengjie avatar  avatar Eder Sosa avatar Mateusz "Serafin" Gajewski avatar Alex Mejias avatar Hitesh Modha avatar William McGann avatar K. Glen Newton avatar Shun Kokubo avatar LPW avatar orociic avatar Ashish Shrestha avatar Senthil Nayagam avatar Matej Ľach avatar tomask.de avatar Shaun (Shanmuganand) Jayaraj avatar Firmansyah Adiputra avatar Dimiter Naydenov avatar  avatar Shwetha Thammaiah avatar Adam avatar Johannes Gilger avatar  avatar decker avatar William Högman Rudenmalm avatar Matias Barletta avatar  avatar Valentin Hăloiu avatar Mark Anderson avatar Kamil Chmielewski avatar Peter Williams avatar Sean Brown avatar Erik Azar avatar Nicholas Marshall avatar Hüseyin Emre Özdemir avatar  avatar Andreas avatar João Saraiva avatar Janez Troha avatar Baotam Nguyen avatar Sparky avatar Dom Delnano avatar Ryad ZENINE avatar Chance avatar metakeule avatar Doug W. avatar Alex Grant avatar Frank Holder avatar Tim Yardley avatar chikamim avatar Pedro Saraiva avatar Bill Turner avatar Michal Molcan avatar Jamie Barton avatar Lubomir Anastasov avatar

Watchers

 avatar Eugene Klimov avatar Jesaja Everling avatar Erik Azar avatar mayulu avatar Johnny avatar K. Glen Newton avatar James Cloos avatar Dominik Schulz avatar Mike Watkins avatar Joshua Magady avatar  avatar  avatar

janus's Issues

Problem installing Janus

When I try to install Janus, I get the following error:

..\github.com\jijeshmohan\janus\server\middleware.go:24: req.BasicAuth undefined (type *http.Request has no field or method BasicAuth)

Auto-generate fake REST API from swagger

I know this would be a huge task and might be better suited as a third-party tool. But I think what would be really cool is if there was a way to auto-generate Janus config from swagger. Many REST APIs use swagger for documentation, and there are a number of tools available to automatically generate client libraries, for example:

So it should be doable to auto-generate janus config from a swagger documented API. It's just an idea but I think it would be cool.

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.