简体   繁体   中英

Rest API and Axios Request

I've written this code:

doIt(evt) {
    axios.get('/book', {
        params: {
            id: 1
        }
    })
    .then(function (response) {
        console.log(response);
    })
    .catch(function (error) {
        console.log(error);
    });
}

I want to get the book with id = 1

I'm using a server running in nginx. I don't know how to receive this request in the server and how to send the response to my client. Help me please.

When you have a JavaScript front end that consumes a REST API back end, you have programming logic at both ends. On its own, nginx is typically used for server static files or reverse proxying - it doesn't have its own way of serving a REST API.

You would typically use a web framework with a database to do the back end logic of serving the API. One example of this is Django with Django REST framework.

Here is an example of how you might set up such a back end stack. Many other web frameworks are available that can be set up with nginx and do a similar job.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM