I have a java based rest server, and my clients will be using Ruby mostly.
What is considered the best practice for URL structure?
This is for JSON only.
Say this is a blog application:
e.g.:
Get all posts:
GET http://www.example.com/api/v1/posts.json
Delete post with id 1:
DELETE http://www.example.com/api/v1/posts/1.json
What about embedded collections like:
Get all comments for post 1:
GET http://www.example.com/api/v1/posts/1/comments.json
View post 1's comment with id 1:
GET http://www.example.com/api/v1/posts/1/comments/1.json
Is there a document that goes over this somewhere? Something fairly "official"?
Apigee has a free e-book on RESTful API design. You have to supply an email address to get it:
http://offers.apigee.com/api-design-ebook-rr/
You're going to find this is a matter of opinion, with no official spec, but your URLs look good to me, and would be in accordance with the guidelines in that book. The possible exception being the last. If 1 is the unique ID of a comment, /posts/1/ may not be necessary.
You could start with the paper that coined REST and look at the URI section:
http://www.ics.uci.edu/~fielding/pubs/dissertation/evaluation.htm#sec_6_2
Bob Aman's well-regarded 2nd answer to this SO question gives detailed guidance:
How to create REST URLs without verbs?
Correctly using the HTTP protocol is the best idea. Read some about the url versioning. http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http
Related
I am currently using fastify (3.20.1) and fastify-swagger(4.8.4). The situation is: I can add all the REST API verbs (PUT, PATCH, DELETE etc.) in my route specification in JavaScript Node Js.
Now I want to add a customized stuff like "Doc" in every section. Something like in the below:
MySection
Doc
GET
POST
I can see the fastify documentation that it supports, quite logically, the typical REST API verbs.
My question is: how can I support another 'custom verb' (like doc).
One way, naively, I can think of: to download swagger ui and add some customization there. But then how can I may register my swagger-ui to fastify.
Please suggest what is the best way to go forward.
Thanks,
Pradip
I am trying to get all of the reddit comments for a particular article.
On the Reddit API page, it seems to suggest that:
www.reddit.com/r/subreddit/comments/ARTICLE
will get me these results (article being a variable), however if I go to an endpoint with the article appended after comments, all I get is a 404 error.
How do you get comments from a specific article via the Reddit API?
I'm doing this in Javascript, but this is obviously a language agnostic question.
reddit's generated API documentation for the comments endpoint appears to be incorrect. The correct URL to use to retrieve comments for a post is:
https://www.reddit.com/r/{subreddit}/comments/{article ID}/irrelevant_string.json
Or for a specific comment:
https://www.reddit.com/r/{subreddit}/comments/{article ID}/irrelevant_string/{comment ID}.json
The "irrelevant string" can be just an underscore, it doesn't matter - on the website itself, it's a form of the title, but the API doesn't care about the title of the post.
I know this is an older post, but I'm posting because I found this when I encountered a similar 404 error when requesting the official api comments endpoint, and while the accepted solution works you can still use reddit's generated api documentation for requesting comments using oauth.
My error (and I'm guessing OP's too) was not stripping the t3_ type prefix from ARTICLE's full name. For example,https://oauth.reddit.com/r/pics/comments/t3_zmvmpn returns a 404, but https://oauth.reddit.com/r/pics/comments/zmvmpn successfully returns the expected comment json.
It's easy to confuse because the official documentation isn't clear on when to use a thing's name vs its id, but when using the json the id field holds the necessary string without the type prefix.
The format when requesting the comments for a given ARTICLE (link) is:
https://oauth.reddit.com/comments/{id}
You can specify the subreddit if you want like in my other examples, but it's not required.
You can give someone an url with get:
http://myserver.com/?var=val
But what to do with POST method ? I know that the program I put url into must support this, I do not know any browser that can (maybe with plugin possible), but is there widely accepted syntax to do it, for example I came up with this:
http://myserver.com/<var=val>
or maybe:
http://myserver.com/??var=val
http://myserver.com/?!var=val
http://myserver.com/!!var=val
http://myserver.com/!var=val
etc...
I'm writing a tool to do it , and I wonder if I must think on my own just like first guy who created e-mail and out of the air conceived # character since it was rarely used then...
The idea is that some services use post data and there is no way to send someone link to resource there. And yes I know that when there is post data that resource is not meant to be such easy passeable to people... but wait since when author of a website has to have power over what I can and can't do with his service.
You'd better introduce a separate argument for passing POST data to your tool. Mixing it together with URL would just cause confusion among your users. Remember that POST data be quite large, so you'd end up introducing features like loading POST data (or a value of an individual variable) from a file anyway.
I have been trying to mess with the twitter4j library for some time now, and cannot seem to get it to work.
The web site and documentation there has proven to be less than helpful, and all the resources I have been able to dig up are really old and most likely irrelevant.
Does anyone have any good resources on this stuff (right now, the oauth portion of it)? I am also trying to use this library via Coldfusion, if that makes a difference.
I have been able to create a (what I believe to be) valid request token and url (as I can get to twitter and login), but when I use the tokens that come back to reconstruct an access token later, it always bombs out with some kind of error...
Yes, the official doc is explaining only basic usages.
Twitter4J is best explained at the example codes located in twitter4j-examples/src/main/java/.
And the community is very active and you can expect getting answers promptly.
http://twitter4j.org/en/index.html#mailingList
Is it possible to get (scrape) data from a site that requires logging in using YQL? If yes, please tell the procedure.
You'll need the user to authorize your access via OAuth, as YQL's docs mention. In addition to the docs pointed to by links from the URL I just mentioned, you can learn all about OAuth here, then get libraries to help you use OAuth, depending of course on the programming language you want to use, from the links listed here.
Depending on how the remote site is set up, you could use a simple POST (there is an open data table for that1) or you could create your own small, custom data table and use <execute>2 to send whatever headers (including Cookie:) you need over one or more GET/POST requests.
htmlpost data table (example)
YQL Execute