REST API Wrapper in Python - python

I am new to Python. I am aware of that, writing RESTful APIs would be easier and secure using some framework. There are already existing RESTful APIs of several 3rd parties. I need to develop RESTful APIs in Python which accepts request in JSON format, validates the request data and behind the scenes call the 3rd party APIs via CURL and sends the response received back to to the consumer in JSON format.
I have been able to do it in PHP using Codeigniter Framework.
Can anyone please provide suggestions on how to proceed for it, some tutorials link, best framework to move with.
Have shortlisted 3 frameworks,
1) Django REST Framework
Prerequisites - Knowledge of Django Framework (Obtained Just enough knowledge)
2) Bottle Framework (Micro framework) -
Explored a bit
3) Flask Framework (Micro framework) -
Yet not explored
Please note, I am having a very small learning curve of just about 5 days.
Please help.

Related

Why Django rest framework is restful?

I'm now writing my engineering thesis about REST and REST APIs, mostly focusing on Django REST framework as it was the framework we used in our engineering project. I just finished writing about the guidelines for API to be RESTful stated by Roy Fielding and I wanted to start section with implementations of REST architecture in Django REST Framework, but then I realized I don't really know why this framework is RESTful. I know what main paradigms are for API to be RESTful, but I don't know what specific parts of framwork inplements for example that our service is stateless or layered. Maybe someone can pinpoint what parts of django rest framework corresponds to specified guidelines for service to be RESTful ? If It's wrong site to ask this type of question then I'm sorry, but any help would be greatly appreciated.
Let's go through the points that make API a RESTful one
1. Client-server architecture
The very essence of the fact that you are developing a backend server, which is not part of your application UI is the point of this client-server architecture.
Every app you develop with Django Rest Framework (from now on DRF) is a backend API, which is separated from the client.
2. Statelessness
I cannot pin point the exact code line that shows why DRF is statelessness but its somewhere deep between Django and the WSGI/ASGI interface.
Somewhere in there you have some kind of code like this:
while True:
request = io.listen_for_request()
response = handle_request(request)
return response
This "very pseudo" code is stateless! why? because we don't save or rely on any information between requests
3. Cacheability
This one is fairly simple, Django and DRF support caching link
4. Layered system
This concept is kinda hard to correlate directly to DRF or Django. This is mainly done through the HTTP protocol.
5. Code on demand (optional)
Servers can temporarily extend or customize the functionality of a client by transferring executable code: for example, compiled components such as Java applets, or client-side scripts such as JavaScript.
Basically Django Templates. It allows you to send forms and pages as part of your endpoints.
6. Uniform Interface
Last but not least, the famous uniform interface. DRF helps you build your REST API interface by creating endpoints with the help of Generic views. Those generic views help you create a full CRUD (create, read...) endpoint on a Django model with little to no effort. The created endpoint follows the Rest API interface of url structure for a resource.

Why do I need web api to link between django and other js framworks

why do i need a web API to link between django and other JS frameworks for example django with angular?
And is it necessary to build a web API like (REST API) to link between back end and front end?
Django is not JS library. It's a Python-based server framework. But your JS library communicates with a server via REST Api. So you need a web API to link between django and other JS frameworks.
Without more work than it is worth, the DJango and Angular frameworks probably cannot pass data between one and the other, since both run at the same logical level in the stack.
REST APIs are the generally accepted mechanism for communicating between SPAs implemented in different frameworks.

How to create a Python API and use it with React Native?

I'm learning about basic back-end and server mechanics and how to connect it with the front end of an app. More specifically, I want to create a React Native app and connect it to a database using Python(simply because Python is easy to write and fast). From my research I've determined I'll need to make an API that communicates via HTTP with the server, then use the API with React Native. I'm still confused as to how the API works and how I can integrate it into my React Native front-end, or any front-end that's not Python-based for that matter.
I think you have to follow some online tutorial
And from my experiences, I think Flask is good choice for such case.
This is basic flask tutorial provided by tutorialspoint.com
You have to create a flask proxy, generate JSON endpoints then use fetch or axios to display this data in your react native app. You also have to be more specific next time.

Python/Django REST API Architecture

I'm trying to build a niche social network like Instagram as a Python/Django application.
So the things I need, regarding architecture, are (I guess):
REST API (e.g. api.mystagram.com).
Public website (www.mystagram.com or mystagram.com).
URL shortener (e.g. mystagr.am).
Android app
iPhone app
Windows Phone app
...
Before this I only built simple to some less-simple websites, but never extremely complex with own custom APIs or so. I have never build my own REST API before (I have used other REST APIs though) or even built an Android/iPhone app and distributed it in the Play Store/App Store (I have made some typical hello world examples though).
So, the most important thing to me seems to create a kick-ass REST API first and proceed from there. I am blocked however by a few questions.
How should I organize the projects for the public website and REST API? Should these be separate Django projects or should I create only one Django project and add both the public website and REST API as an internal Django module?
Should the public website also make use of the REST API? Or is it better to just use the plain Django models for this?
Thanks in advance for any help! If somebody knows some great presentations or so on this topic (architecture), always welcome!
Kind regards,
Kristof
Django REST Framework
https://github.com/tomchristie/django-rest-framework
Very well maintained, great documentation, easy to use.
I think Tastypie will do what you want. And its simple and easy. Check this out - http://django-tastypie.readthedocs.org/en/latest/!
To Answer your first question, It would be good practice to put public web site and REST APIs into one django project. Now days every web application contains public web site as well as rest apis for mobile app. So it would be easier to maintain both website and rest apis if they both in one application. Below is Django REST Framework link.
https://github.com/tomchristie/django-rest-framework
For second question, Yes you can use rest apis in website also. But in general you don't need to do it. In most of the cases django model works for you.

RESTful Python WSGI web framework [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Recommendations of Python REST (web services) framework?
I'm looking for a RESTful Python (preferably Python 3) web framework. It should have the following things:
configurable URLs
URL generation
support for file uploads
authentication (http basic auth, cookie based)
content-negotiation
based on WSGI
ability to answer requests with HTTP verbs not supported by the requested resource correctly (example: if someone sends PUT but the resource only supports POST and GET, the application should answer with the allowed methods POST and GET)
support for caching headers
transform/render results
What would you recommend?
pyramid 1.3 has python 3.2 support
http://www.pylonsproject.org/projects/pyramid/about
docs: http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/
requests: http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/webob.html#request
view config decorator: http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/viewconfig.html
gives the ability to write specific views for each request method to the same route e.g.
#view_config(route_name='wiki', renderer='base.pt', request_method='POST')
def view(request):
return {'a': None}
#view_config(route_name='wiki', renderer='base.pt', request_method='PUT')
def view(request):
return {'a': None}
you should glance at this link, Recommendations of Python REST (web services) framework?
in this link #martin has gave really good example for developing your own rest-api. i dont know any RESTful framework which meets your all needs but you can develop your own.
and you can check Flask and Bottle. they are fast, simple and lightweight WSGI micro web-framework for Python...
It sounds like you have a good bit of experience with HTTP. You should check out CherryPy, which is much more of an HTTP framework than a web framework. That point of view allows you to leverage HTTP in ways that the other frameworks generally try to hide from you. CherryPy can do all of the things you requested: flexible configuration is one of its selling points, and it ships with tools for caching, the Allow header, auth, and negotiation. Version 3.2 abandoned the restrictive cgi module for processing uploads and now supports upload temp files, streaming, and automatic pre-processing based on media type.
The non-blocking webserver and framework Tornado looks promising. It's a bit like web.py with an event driven model like the JavaScript framework node.js (but with a more convenient language). But I have not tested it yet.

Categories

Resources