S
S
SuperAndrew12022-01-20 12:30:53
API
SuperAndrew1, 2022-01-20 12:30:53

How does the API work without hosting folders?

If the hosting in my domain has a folder folder at the root (and at least index.html in it) - I can go to https://domain.com/folder

If the folder contains, for example, folder 1 (and in it also index.html) - then I can go to https://domain.com/folder/1

But how does this work in the case of the API? For example, in Laravel or Django, you do not need to create a separate folder in order to change an entry with some id in the database, but if I go to https://domain.com/api/user/1/delete (and such a path I don’t have it on hosting) - I don’t get 404, but what happens is what is written in the controller. But if I go to another path, which is also not on the hosting (for example, https://domain.com/adfdfg4/asdf32w4rfefds/) - it will give 404, because this folder does not exist.

In both cases, these folders are not on the hosting, but for some reason using api does not knock out 404. How does it work?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dr. Bacon, 2022-01-20
@bacon

url routing, and how it works, I would take and read the documentation from the corresponding framework
PS direct display of folders in url, this is something from the past or the year before last. And well, yes, or for static pages.

R
Rsa97, 2022-01-20
@Rsa97

Redirection is done in the site settings (for example, via .htaccess).
The address https://domain.com/api/user/1/deletecan be directed to

https://domain.com/api/index.php?request=/user/1/delete
.

R
Rag'n' Code Man, 2022-01-20
@iDmitriyWinX

Program on some NodeJS and you will immediately understand everything.
There, a request is simply tracked for some path, and if there is a handler for this path, it is called.

const requestListener = function (req, res) {
    res.setHeader("Content-Type", "application/json");
    switch (req.url) {
        case "/books":
            res.writeHead(200);
            res.end("hello world");
            break
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question