how should I create good rest api? [closed] - python

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.

Related

Need help on program that uses facebook/instagram info [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 1 year ago.
Improve this question
A client wants to have information about public instagram/facebook profiles (photos/videos published, total likes/comments) from a period of time. How do I go about doing this?
I found out that some of that information is available in the website source code, but how do I use that information? Also is there any sites/services that does that already? The only ones I found only go as back as a few weeks, or only procress future posts.
I thought about automatizing the process with python, is it a good idea?
I'm new in programming, so any help is aprecciated.
As far as I know Instagram is trying to limit as much as possible bot activities, I'm not sure about Facebook though.
You can definitely try to webscrape (using python or other tools) the information you need but if things don't work, it may not be your fault.

REST API vs non-REST 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 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.

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 :)

Get Form Data over Network [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to make a program that will get form data. So whenever anybody on a local network submits form data to a website, I would like to see that data being submited. Is this possible? If it is, is it possible in python? Thank you.
If I'm understanding your requirements correctly, you want to listen for packets on the local network and filter out everything but POST (which would be submitting form data). If I were you, I would look into wireshark, capture all the packets, filter out all that aren't POST to the specific website.
Wireshark has a Python API, and you may find this stackoverflow question of interest.
Hope I helped a little.
You may want to look at mitmproxy as it is easy to setup and may address your core needs. Bonus, it's pretty easy to set up across devices.
Disclaimer - if you are doing this without the knowledge or consent of those on your network, you're likely breaking the law.

How to write basic webpage in python without using framework? [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
Could you please tell me, How do I write a basic webpage without using framework like Django, Web2Py and others third party frameworks. Also, I don't like to use CGI for it. I need basic MVC structure with a hello-world web page only.
I suppose you mean a http server, because for a webpage only, you'd use html, not python.
I suggest you start with some reading on this page. It's the http server for python. As you want to keep things easy, you probably just want to overwrite the BaseHTTPRequestHandler or the SimpleHTTPRequestHandler classes, especially the do_GET and do_POST methods.
Note that this won't force you to use MVC, that's your own responsibility. You'll need an actual framework if you want to enforce MVC.

Categories