Graphql Wrapper for Rest APIs with Django - django

Trying to implement wrapper for existing REST APIS using Django graphQL.
Found similar one in JS but not in Django.
https://graphql.org/blog/rest-api-graphql-wrapper/
Could anyone please suggest if there is a GraphQL Django wrapper for REST calls. Haven't found in documentation either

Are you talking about a rest API using DRF? I'd suggest you look at graphene-django-cud to help you with mutations. Graphene-django is required for this, and will help with your queries. Unfortunately it's not a wrapper that will convert all your DRF code into graphql, however you should be able to basically copy paste a lot of the content in your serializers/views.

Related

Django API without DRF: What are the consequences

I'm not sure what might go wrong when I have to integrate a django API (built using JsonResponse and without extra frameworks) with a frontend, in this case, Next.js.
I built a django API using JsonResponse (void of DRF). I want to build a frontend client with Next.js that would make API calls to my django API. My questions are:
Will I have to run both django and next.js servers at the same time to execute the full project?
I think I would face some challenge with csrf token, what other challenges may I face having built my API without an API framework as Django Rest Framework?
It is almost always a better approach to treat these two as separated as possible. I'd go with completely separate repos, hosting etc...
I think the biggest advantage of using DRF is the validation. DRF has nice ways to handle request data validation. Your views will look much leaner, because it will save you the trouble of writing much boilerplate code.

Advantages of using REST API framework over simple URL and view creation in Django?

It might be a silly question for many, but why can't I instead
Create a view in django that takes a request and returns HttpResponse in, say, JSON format
Map the view to a URL
Hit the URL from my browser or another server and use the result?
Thanks.
EDIT - Two approaches: Import some djangorestframework or tastypie and build an api in my application which will throw json responses VS building a view and tell it to return json response. Is there any huge advantage of using the first one?
I think you could make the same argument about any extension library. It just depends on how much you want to rebuild and what the existing library has that would be beneficial to your project.
Many times I've created custom endpoints without an API library when working with ajax requests inside my project. For that instance, using an API package is overkill. But for having a full API server, Django rest framework offers a lot of functionality.
Sure, you can make views that do what you suggested. But at some point are you going to want to authenticate through an HTTP request? Are you going to want to filter? Are you going to want to make permissions, or just have all endpoints open? Are you going to want to protect against CORS?
You can kind of go down the list of all the features of an API library and ask these questions about what you want to accomplish with your project. If you're working with any type of external application and your django project is just for an API server, usually it's best to go with Rest Framework. If you just have some one-off endpoints to receive ajax requests, usually you just want to build custom endpoints.

Django app without ORM Model, but using data from a Public REST API

I am wondering if it would be possible to create a Django app which doesn't get it's data from the default Django ORM, but from a third party REST API? Is that at all possible? And if it it, does anyone have any pointers to examples or further reference ?
From what I have found up till now I can use django-rest-framework to build a REST API on top of a Django ORM model. In my case I won't have a Django ORM Model since all information will be coming and going through a third party REST API (JSON or XML).
By definition Django is ORM framework so not using the ORM is kind of pointless, however it is very rich fullstack framework so it is absolutely possible to use just some components of it like template system or routing. If you don't want the orm just don't use it.

Django + AngularJS: Recommendations on restful integration

Does anybody have any recommendations on how to integrate AngularJS with a current Django project? I have no experience with AngularJS but I like the asynchronous loading and update of objects, so it seems time to learn. There seem to be a lot of django and AngularJS pypi apps, but is that the best way to integrate?
Any advice on AngularJS integration with Django would be great.
Thanks
you could develop REST api, which returns responses in rest format, you could use tastypie for example.
Related topic how to return in json is here Django-tastypie. Output in JSON to the browser by default

How can I create a oauth (REST) API ( like twitter or foursquare ) using django?

I would like to create an oauth (REST) API the same way Twitter or Foursquare does.
I found this website http://djangopackages.com/ which is really great and has several packages but I would like some opinions on which is the best package, etc...
I would like, for example, let people to allow permission to 3rd party apps to access their data (Using API Keys, etc...)
Thanks a lot!
Django is a wonderful web framework. It helpes you in many ways making rich web applications. It helps you starting in form handling and ending in templating.
However in your case if your intension is just to make an awesome API such as of Twitter or Foursquare, you have to ask yourself if you need all this help Django provides. For example, are you ever going to use any templates in the API or process a for submittions. The answer is probably not...
So if you need a very flexible framework to developer an API, I would highly recommend to take a look into Pyramid. It is very similar to Django, however does not have all this extra cludder which is not necessary for an API.
However if your application needs both a rich user interface and an API or you just want to use Django, like Ulusses suggested, then I think TastyPie is for you. It is a great library where you can have a running API in no time. I use it all the time and it is very flexible. ReadTheDocs uses tastypie.
Another API lib is piston. I haven't used it so can't judge if its better or worse then tastypie. Bitbucket however uses it.
You can check out https://github.com/toastdriven/django-tastypie or https://bitbucket.org/jespern/django-piston/wiki/Home.
You can achieve what you want with both, check out on the documentation the one that suits you best.
I use Django REST framework. It is awesome.
Piston is dead. Tastypie is awesone, but works with Django only. There are pros and cons with Django as well as Pyramid. If you need great ORM, sqlalchemy is only one, and there is no good example of using it with Django, so in this case you have Flask, Bottle or Pyramid. Django ORM is really not at that par.
If you choose Pyramid, you will have to write a lot of things, and the framework is just skinned boneless cat. You need to assemble and configure every block, seems frustrating to many including me.