REST API vs non-REST API [closed] - python

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I read about REST API specifications. These are the principles:
everything is a resource
each resource is identifiable by a unique identifier
use the standard HTTP methods
Now suppose there is a table for contact details
id , owner, contact name,contact number, created At
I want to design an API to consume the data. I can design the api in the following ways.
For getting the contact by owner
Get /contact/owner/david
or
Get /getContactByOwner?ownerName="david"
For writing into the table
post /contact/owner
{contactDetail JSON in request param}
or
post /addToContact?owner="john"&...
Which design is RESTful? What is wrong with the other one?

The rule of thumb with RESTful naming conventions is to use nouns as your endpoints (since your verbs should be limited to get / post / put / delete / etc). So in your example, Get contact/owner/david and Post contact/owner would be preferable. However, if you're really using REST architecture, you should technically be using HATEOAS (Hypertext-as-the-engine-of-application-state) and including links in XML or HTML responses, so if you're using JSON it's probably more REST-like as opposed to full-blown REST. At the end of the day, it's all a matter of preference; just try to use whatever will fit the needs of the application's users in a way that's somewhat self-documenting and intuitive.

Related

How to use request(python) to use Microsoft Graph API [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I tried to use the Microsoft Graph API from the Request module in Python, but I was still new and didn't want to use Postman either. But I had a problem using the Request module:
How to select the application platform type?
How to fill in the redirect URL?
How to get refresher token and access token ?And how to renew(refresh) them?
How to get Tenant ID?
This is all my questions. I hope someone can help me solve them.
(This question by the machine translation, if there is a small mistake, also hope you understand.)
Congrats on your first question!
This is not a full answer that you might have been looking for, but take a look at the Microsoft Graph API docs
After you register your app and get authentication tokens for a user or service, you can make requests to the Microsoft Graph API.
Did you register your app? If not here are the docs
In your question it looks like you're describing the flow for get access on behalf of the user, but what you need is get access without a user. In order to use the API through the requests module you need to follow this tutorial

Get and transfer data using an API [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I have to develop an API to manage data between my Database in PostGreSQL and my website in Django.
I'm actually looking for the best way to manage and transfer this data, what I actually found on different topics / sites is the Django Rest Framework to develop a Rest API in Django, here I would use a JavaScript framework for the front like React, Angular or VueJS (any tips about which one to choose ? ).
I was wondering if there was other solutions that would be interesting ? I've been searching about FTP or things like this.
Thanks,
Lucas
Like you said you need to send and retrieve information like name, contact, login detail etc related to user and their subscriptions.
In this case you don't have to think about FTP. It isn't related here. FTP is something that you'll use to transfer files without django.
With django you will have to use DRF (django rest framework) or use GraphQL along.
There is a package well known to use GraphQl called graphene
For front end part you can use anything according to your requirement and skillset.
Hope this helps.
Cheers

Can somebody explain me what is the use of "etag" in django? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am confused with the etag mechanism. If anyone could explain it, would be a big help
So first lets separate etags from django/python. The concept of etags, lives independently of any programming language. It is actually part of HTTP.
Simply put etags are part of the way one might go about implementing a web cache. Basically the server returns an ETag header which is a hash that represents the state of a resource. The client can then send that hash value to the server which can perform a check, if it matches then the cache the client has is still valid 304. If the values are different then the server would send a full response back to the client.
Basically outlined on Wiki :)

Is Django suited to simple webapps? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm diving into Django to create a webapp.
The thing is, I'm not sure if my app is too simple for what Django offers.
My app will download the latest CPI figures and convert your (monetary) dataset into inflation-adjusted figures, going way back in decades. The user pastes their data in via a textbox. It certainly won't need SQL.
I may want to expand the project with more features in future.
Is it advisable to go with a more lightweight framework for something as simple as I've described?
Every framework has its pros and cons. There are many different frameworks. Personally I prefer Flask but it is all personal preference. Here are some articles that help describe the differences:
https://www.airpair.com/python/posts/django-flask-pyramid
https://www.reddit.com/r/Python/comments/1yr8v5/django_vs_flask/
https://www.hakkalabs.co/articles/django-and-flask
A webapp like the one you describe sounds like most of the work can happen on the client side, without sending the data back to server. From what it sounds like, you simply need to make a few calculations and present the data in a new way.
For this I don't recommend Django, which is ideal for serving pages and managing relational DB content, but not really useful for client side work.
I'd recommend AngularJS

how should I create good rest api? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
to get posts for a user:
GET http://test.com/users/123/posts or GET http://test.com/posts?user_id=123
to get new posts count:
GET http://test.com/posts/count/new or http://test.com/new_posts_count or others?
This is a good read: http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api.
And in terms of the two formats you suggested: I prefer the former.
Doesn't matter from a REST point of view (REST doesn't define URI structure). The client should not know the URL structure before hand so technically it doesn't matter to the client either.
I personally prefer the first style as I think it makes more sense when you have a resource hierarchy. It also allows a client to move back up a URI by simply chopping off the end resource, similar to how you can go back up a directory on a file system by simply clicking the parent button.
But there is no "right answer" to this from a REST point of view. REST is concerned with the transfer of state of resources, not the resource hierarchy or URI definition.

Categories