what actually is a REST api? Can someone provide an example it, and an example that isn't it?
Can someone please explain like Im 5.....what a REST API is?
First of all you should be familiar with some HTTP methods, and basic terminology. API stands for Application Programming Interface. This may not tell you much on it’s own if you can’t solidify what application and programming interface means.
Well, defining application is easy and you can probably refer it yourself. Any one or many “programs” or functionality coming together to be used by an end-user towards a need or a purpose is an application.
The word interface in software is used as “an endpoint of an application that an end-user can interact with”, it’s short for human - software interaction. But there’s more to it when you generalize from a real example.
Say that you have loaded the search engine, Google’s homepage. You are met with an interface. So far, this interface has already served you a resource, the search form, logo and all. On it you notice it can possibly do more than just showing you a single page. There’s an input area, and a button. You type in your favorite network, Reddit, and click search. Conguratulations, you have just interacted with the interface, you’ve sent data to it. Now it returns you new resources, web pages that are listed based on your search term. You have now defined that “an interface helps you interact with resources by certain actions.”
You might have felt a bit constrained while using Google. Why the hell can’t you change some of the results or add your own into them? Well, that’s because you’re not authorized to do so. But worry not, an interface will also enable that, as long as you have the correct “passport” for it. You were interacting on Google’s interface at the public level, what you can do, anyone can.
A programming interface is only different at one end-point, you. It’s for different programs to interact with each other, not humans. To make this interaction process more universal, HTTP methods were introduced into web APIs. That “universal” behavior made what’s now called REST API. These API ends are usually token-authenticated, especially if they also allow operations besides retrieving data.
Now for the HTTP methods used in REST APIs. These are:
GET: Our good old, classic way to ask for a resource. This is what you did by loading Google’s homepage, and you didn’t notice it but when you searched with a keyword, you also did this to get the listings! (Like: GET /user/1 or GET /users)
PUT: This is like, exchanging your Pepsi for your friend’s Coca Cola (Sometimes it’s too late for your friend to notice that you don’t have a Pepsi).
In context, PUT replaces a resource completely, even if it doesn’t exist. So it also has a way of saying “replace that empty resource with a not-so-empty one”, meaning it can also create! But usually you’ll see POST being used for creation, PUT for updating. (PUT /user/1 or PUT /user if it’s an insert)
PATCH: You posted a comment on a regex replace question on r/learnpython, being silly you used “$1” for match replacement instead of “\1”. In quick shame, before people notice your Perl-syntax you edited and updated your comment, it was only a partial error you had to correct.
While PUT is for replacing a resource completely, PATCH is usually used to replace partial data. It is valid for existent resources, meaning unlike PUT it won’t create if there’s no such resource. This sad little thing is not as often used, due to POST/PUT preference over PUT/PATCH. (PATCH /user/1)
POST: You posted this thread, whee!~ It wasn’t here before, you created it, now you have a URL for it to reference as well, whether you want to see it again, edit it, or... (POST /user)
DELETE: ... delete it. You want this post gone? Sure, the post probably feels the same way! (DELETE /user/1)
In general, created resources return an id (resource identifier) for you, update and delete operations require such an id, for listing it can be optional. You can GET a specific resource with it’s identifier or refer to it’s container to get all the resources within it. REST APIs commonly communicate with either JSON or XML, mostly JSON nowadays.
If the word resource is too vague, it’s because it’s meant to be. A resource can literally be anything, but in general, it’s a/group of a data.
If you have any other questions, feel free to ask, I’ll be happy to answer them!
More on reddit.comREST APIs are obsolete
ELI5: What is RESTful API?
What is REST?
What is an API?
Videos
I've heard what a REST api is, I know what REST stands for, and I'm pretty sure I've worked with them before. But I can't say I understand at a deep level what it actually means, and I couldn't look at a given api and say "yep this is REST because XYZ" or "nope, this isn't REST because XYZ".
Can someone give me a concrete example of both an api that is considered REST and an api that isn't? I want to be able to pinpoint the defining characteristics