GithubHelp home page GithubHelp logo

tornado-rest's Introduction

PyRestful

pyRestful is an API to develop restful services with Tornado Web Server.

We made changes from the last version to improve it and make it more easy.

With this API allows service development rest allowing access to resources, as follows (see the demos).

The API allows develop a CRUD over the resources. In this example the resource is Customer.

GET: http://myserver.domain.com:8080/customer/{id}

 GET /customer/1 HTTP/1.1

 GET it is equivalent to SELECT.

POST: http://myserver.domain.com:8080/customer

 POST /customer HTTP/1.1
 Host: myserver.domain.com
 
 customer_name=Rodrigo&customer_address=Santiago

 POST it is equivalent to INSERT.

PUT: http://myserver.domain.com:8080/customer/{id}

 PUT /customer/1 HTTP/1.1
 Host: myserver.domain.com
 
 customer_name=Rodrigo&customer_address=Santiago
 
 PUT it is equivalent to UPDATE.

DELETE: http://myserver.domain.com:8080/customer/{id}

 DELETE /customer/1 HTTP/1.1

 DELETE it is equivalent to DELETE.

PyRestful implements the verbs get, post, put and delete.

Installation

You must have installed python 2.7 and tornado-3.x.

Download the api from github (https://github.com/rancavil/tornado-rest/archive/master.zip).

Unzip the file tornado-rest-master.zip

 $ unzip tornado-rest-master.zip

Go to the directory and install.

 $ cd tornado-rest-master
 $ python setup.py install

Or you can install it using.

 $ pip install pyrestful

(https://pypi.python.org/pypi/pyrestful/0.3.1.alpha)

Echo Rest Service

This example implements a Echo Rest Service (echo_service.py).

Write the next code and save echo_service.py file.

 import tornado.ioloop
 import pyrestful.rest

 from pyrestful import mediatypes
 from pyrestful.rest import get

 class EchoService(pyrestful.rest.RestHandler):
      @get(_path="/echo/{name}", _produces=mediatypes.APPLICATION_JSON)
      def sayHello(self, name):
           return {"Hello":name}

 if __name__ == '__main__':
      try:
           print "Start the echo service"
           app = pyrestful.rest.RestService([EchoService])
           app.listen(8080)
           tornado.ioloop.IOLoop.instance().start()
      except KeyboardInterrupt:
           print "\nStop the echo service"

Execute the service with.

 $ python echo_service.py

Then in a browser write the url.

 http://localhost:8080/echo/rodrigo

You should see the following output in your browser.

 {"Hello": "rodrigo"}

tornado-rest's People

Contributors

rancavil avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.