jbradforddillon / instant-api-py

A python script that creates a simple server from a given JSON file.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is this?

This is essentially a python implementation of Waldo Jaquith's instant-api, but with a few handy bonus features. It creates a basic RESTful web service using a JSON file as source.

Usage

Unlike it's PHP counterpart, this script doesn't require a running web server with PHP, it uses python's own HTTPServer. Just run it from the command line, like so:

$ ./instant-api.py

To specify the port and/or file to serve, just use the --port and --file attributes, respectively:

$ ./instant-api.py --port 8080 --file source.json

One other minor difference/improvement: this script uses the friendlier/path/format rather than ?query=strings, and can go several levels deep in the JSON, with support for arrays.

Example

Given this JSON:

{
	"colors" : [
		{
			"name" : "Red",
			"hex" : "#FF0000"
		},
		{
			"name" : "Green",
			"hex" : "#00FF00"
		},
		{
			"name" : "Blue",
			"hex" : "#0000FF"
		}
	]
}

You could use this:

http://localhost:8080/colors/1

To retrieve this:

{
	"name" : "Green",
	"hex" : "#00FF00"
}

Licensing and Contact

MIT License. Find me on twitter (@jbradforddillon).

Inspired by Waldo Jaquith

About

A python script that creates a simple server from a given JSON file.


Languages

Language:Python 100.0%