Skip to content

Instantly share code, notes, and snippets.

@spro
Created June 17, 2015 07:39
Show Gist options
  • Save spro/7c929c5213253e054a04 to your computer and use it in GitHub Desktop.
Save spro/7c929c5213253e054a04 to your computer and use it in GitHub Desktop.
Overly simple REST API with Bottle.py
import bottle
import json
all_people = [
{'name': 'Fred Wilson'},
{'name': 'Fred Durst'},
{'name': 'Fred Astaire'},
]
@bottle.get('/people.json')
def list_people():
return json.dumps(all_people)
@bottle.get('/people/<person_id:int>.json')
def get_person(person_id):
try:
return json.dumps(all_people[person_id])
except IndexError:
return bottle.abort(404)
@bottle.post('/people.json')
def create_person():
new_person = bottle.request.json
all_people.append(new_person)
return json.dumps(new_person)
bottle.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment