4

BACKGROUND:

I have a REST API implemented in Java using Jersey. My API uses four verbs: GET, POST, PUT, DELETE. I find developing REST APIs in java very easy and straight forward.

eg here is an elaborate hello webservice (I say elaborate because there are easier ways, but this is more representative):

import javax.ws.rs.*;

@Path("/myresource")
public class MyResource{

   @GET
   @Path("name/{name}")
   @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
   public Response sayHello(@PathParam("name") String name){
       return Response.ok("Hello "+name).build();
   }
}

PROBLEM:

I am learning python. I want to convert my Java Jersey REST API into python.

Basically Jersey is Java's implementation of REST (aka JAX-RS: Java API for RESTful Web Services). Does python have a reference implementation of REST? If not, is there any implementation out there that comes close and would be easy to use for someone coming from Java-Jersey?

androfactured
  • 175
  • 2
  • 8

1 Answers1

4

You may want to check the previous similar question: Recommendations of Python REST (web services) framework?

Python does not have a built-in REST framework, but I personally have had good experiences with Flask and Bottle.

It's very similar in use to Jersey (Bottle example):

@route('/')
@route('/hello/<name>')
def greet(name='Stranger'):
    return template('Hello {{name}}, how are you?', name=name)

Handling HTTP verbs:

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        do_the_login()
    else:
        show_the_login_form()
Community
  • 1
  • 1
BoppreH
  • 8,014
  • 4
  • 34
  • 71