1
1
123qwe2016-03-17 18:06:59
API
123qwe, 2016-03-17 18:06:59

Am I understanding the restfull api principle correctly?

What is up, programmach.
I create a number of methods (library) that return this or that information, for example, about pictures. If I created a gallery.
I write the address of my site, and if I need to get info in json format on my pictures, I write in the address bar:
www.mysite.edu/gallery/new_pictures/getPictureInfo(5)
Assuming that I have a ready-made getPictureInfo method in the library , which returns information about the picture in json format. I passed the id of the picture as a parameter (key).

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Makarov, 2016-03-17
@Nipheris

I create a number of methods (library)

This is RPC style. See RESTful API and MVC - what is it?

A
Alexander, 2016-03-17
@SashaSkot

Not certainly in that way.
REST web service architecture works a little differently.
The http protocol has several methods by which you can interact with a web server.
Each of the methods is necessary for a different action on objects in the web service. For example, GET server.ru/picture/1234556
This request receives a picture with the identifier 1234556.
If you use the DELETE method, then delete the picture.
POST - to add, for example, POST server.ru/picture in the body, transfer the contents of the picture.
Etc.
Apache uses mod_rewrite module rules for REST.
For example - such a request server.ru/picture/1234556- set to some page - server.ru/getpicture.php?id=1234556.
Etc.
A URL rule in REST is usually an object.
That is, server.ru/picture - works with the Picture object.
server.ru/catalog with a catalog, etc.

_
_ _, 2016-03-17
@AMar4enko

REST is just a convention. Just like the variable naming convention or callback function signature convention in nodejs.
REST can make your life easier, and it also allows you to use client-side REST-style APIs.
The API itself only means returning data in a machine-readable format (well, some documented set of input data, of course), because the API is an Application Programming Interface, i.e. a tool that allows third-party applications to interact with your development.
For example, GET mysite.ru/news/article.html is probably not an API method, because it will most likely return the already formatted html
GET mysite.ru/news/article.json- probably an API method, because it will most likely return the article data in JSON
.html and .json here for clarity, you can also tell the server through the header what type of content you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question