Tag Archives: Web Services

A “RESTful API” in just 3 minutes with Python and Bottle

Hi. This post show a simple and fast way of implement a API server using web services in python

Ingredientes:

Python, Bottle and Route (if you wish test it using a curl style command from python)

Installation (From Terminal)

sudo pip install bottle
sudo pip install requests

Once installed, run python and write (or paste):

from bottle import route, run
@route('/hello')
def hello():
 return "Hello World!"
run(host='localhost', port=8080, debug=True)

After that server is running, open a new terminal console with python and run the following commands to test you server. Note that we a using here a CURL linux’s like command for Python. (Also you could open the  url directly in you browser):

import requests
for i in xrange(1000):
requests.get('http://localhost:8080/hello/world', auth=('user', 'pass'))

And there you are!
Bye

Advertisements