简体   繁体   English

Rest API 和 Axios 请求

[英]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我想得到 id = 1 的书

I'm using a server running in nginx.我正在使用在 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.当您有一个使用 REST API 后端的 JavaScript 前端时,您在两端都有编程逻辑。 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.就其本身而言,nginx 通常用于服务器静态文件或反向代理 - 它没有自己的方式来提供 REST API。

You would typically use a web framework with a database to do the back end logic of serving the API.您通常会使用带有数据库的 Web 框架来执行为 API 提供服务的后端逻辑。 One example of this is Django with Django REST framework.这方面的一个例子是带有 Django REST 框架的 Django。

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.许多其他 Web 框架都可以使用 nginx 进行设置并完成类似的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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