直接从 API 服务器使用 API 结果填充网页 [英] Populate web page using API result directly from API server

查看:19
本文介绍了直接从 API 服务器使用 API 结果填充网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先很抱歉,如果之前有人问过这个问题,但我是新手,所以即使它有我也不知道我什至会用来尝试寻找它的语言.

Firstly sorry if this question has been asked before but I'm a novice so even if it has I'm unaware of the language I'd even use to try and seek it out.

我开始学习 REST API,这让我开始思考.是否可以将 JSON 响应直接从 API 服务器加载到用户的浏览器中并绕过您自己的服务器?

I'm beginning to learn about REST API's and it got me thinking. Is it possible to load the JSON response directly from the API server into the user's browser and bypass your own server?

假设您有一个在服务器上运行的 Django 应用,该应用使用图形 API 访问来自 Outlook.com 的电子邮件.

Imagine you have say a Django app running on a server that accesses email messages from Outlook.com using the graph API.

我假设一个普通的流程是这样的:用户请求->您的服务器->图形api->您的服务器->用户浏览器.

I assume an ordinary flow would go something like: User request->your server->graph api-> your server-> user browser.

在它继续呈现给用户的浏览器之前第二次访问您的服务器似乎是一种浪费.

It seems like a waste for it to hit your server that second time before it goes on to be presented to the user's browser.

Django 应用程序是否可以呈现模板并有效地告诉浏览器期望来自 X 源的一些数据,并将其放置在此模板中的 y 位置"?

Is there a way the Django app can render a template and effectively tell the browser "expect some data from X source, and place it in y location in this template"?

推荐答案

您可以使用 javascript 做到这一点.您必须在模板中包含脚本标记,或者在代码中创建并包含一些静态 javascript 文件.

You could do that with javascript. You'd have to include either a script tag in your template, or create and include some static javascript files with the code.

我建议学习和使用 jQuery javascript 库,因为它使您所谈论的内容更加丰富更容易实施.研究ajax请求,这些是你直接向另一台服务器发出请求所需要的,绕过你自己的

I'd recommend learning and using the jQuery javascript library, as it makes what you're talking about much easier to implement. Research ajax requests, those are what you'll need to make requests directly to another server, bypassing your own

这篇关于直接从 API 服务器使用 API 结果填充网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆