All Projects → jijeshmohan → Janus

jijeshmohan / Janus

Licence: mit
Janus is a fake rest api server

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Janus

Musoq
Use SQL on various data sources
Stars: ✭ 252 (+135.51%)
Mutual labels:  utility, tool
Fselect
Find files with SQL-like queries
Stars: ✭ 3,103 (+2800%)
Mutual labels:  utility, tool
Laravel Zero
A PHP framework for console artisans
Stars: ✭ 2,821 (+2536.45%)
Mutual labels:  utility, tool
Jql
A JSON Query Language CLI tool
Stars: ✭ 368 (+243.93%)
Mutual labels:  utility, tool
Common.utility
Various helper class
Stars: ✭ 4,101 (+3732.71%)
Mutual labels:  utility, tool
Search Deflector
A small program that forwards searches from Cortana to your preferred browser and search engine.
Stars: ✭ 620 (+479.44%)
Mutual labels:  utility, tool
K2tf
Kubernetes YAML to Terraform HCL converter
Stars: ✭ 477 (+345.79%)
Mutual labels:  utility, tool
Scelight
The source code of the Scelight project with all its modules.
Stars: ✭ 97 (-9.35%)
Mutual labels:  utility, tool
Json2dart
Stars: ✭ 103 (-3.74%)
Mutual labels:  tool
Restful Api Guidelines
A model set of guidelines for RESTful APIs and Events, created by Zalando
Stars: ✭ 1,397 (+1205.61%)
Mutual labels:  rest-api
Grest
Build REST APIs with Neo4j and Flask, as quickly as possible!
Stars: ✭ 102 (-4.67%)
Mutual labels:  rest-api
Icmethoddigger
An easy way to print almost methods including private methods (supported arm64 architecture devices).
Stars: ✭ 103 (-3.74%)
Mutual labels:  tool
Multicolour
🌈 Generate a REST API in minutes with almost any DB tech. 🌈
Stars: ✭ 104 (-2.8%)
Mutual labels:  rest-api
Npm Try
🚆 Quickly try npm packages without writing boilerplate code.
Stars: ✭ 103 (-3.74%)
Mutual labels:  tool
Cloudbookmark
云书签
Stars: ✭ 106 (-0.93%)
Mutual labels:  rest-api
Machina
Network capture library for realtime TCP/IP decoding from a windows application. Includes an extension library to support FFXIV data capture.
Stars: ✭ 102 (-4.67%)
Mutual labels:  utility
Swagger Express Ts
Generate and serve swagger.json
Stars: ✭ 102 (-4.67%)
Mutual labels:  rest-api
Airdcpp Webclient
Communal peer-to-peer file sharing application for file servers/NAS devices
Stars: ✭ 106 (-0.93%)
Mutual labels:  rest-api
Wp Rest Starter
Starter package for working with the WordPress REST API in an object-oriented fashion.
Stars: ✭ 105 (-1.87%)
Mutual labels:  rest-api
Lens
A utility for working with nested data structures.
Stars: ✭ 104 (-2.8%)
Mutual labels:  utility

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].