Skip to content

mmautner/simple_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demo RESTful HTTP API using Flask, Flask-Restful and SQLAlchemy

  1. Install requisite packages:
$ pip install -r requirements.txt
  1. Create tables:
$ ./models.py
  1. Run service:
$ python app.py
  1. Give it a try:
>> import requests, json
>> requests.get('http://localhost:5000/todos').json()
[]
>> requests.post('http://localhost:5000/todos',
                 headers={'Content-Type': 'application/json'},
                 data=json.dumps({'task': 'go outside!'})).json()
{u'id': 1, u'task': u'go outside!', u'uri': u'http://localhost:5000/todos/1'}
>> requests.get('http://localhost:5000/todos/1').json()
{u'id': 1, u'task': u'go outside!', u'uri': u'http://localhost:5000/todos/1'}
>> requests.put('http://localhost:5000/todos/1',
                headers={'Content-Type': 'application/json'},
                data=json.dumps({'task': 'go to the gym'})).json()
{u'id': 1, u'task': u'go to the gym', u'uri': u'http://localhost:5000/todos/1'}
>> requests.delete('http://localhost:5000/todos/1')
>> requests.get('http://localhost:5000/todos').json()
[]

Don't forget that you must pass a "Content-Type: application/json" header along with your request!

About

a basic Flask/Flask-Restful/SQLAlchemy REST API service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages