简体   繁体   English

如何为REST API后端构建REST客户端前端?

[英]How to build a REST client frontend for a REST API backend?

I've built a REST API backend using Django and am now at the stage of designing a client facing frontend. 我已经使用Django构建了REST API后端,现在处于设计面向前端的客户端的阶段。 Though, I can't seem to understand how this client frontend should be structured and which languages it should use. 虽然,我似乎无法理解该客户端前端应如何构造以及应使用哪种语言。

PHP is server-side, and is usually used as the language for building backends. PHP是服务器端的,通常用作构建后端的语言。 When coupled with a framework such as Codeigniter, it can also be used to play around with sessions, route URLs, and decide which templates to use. 当与诸如Codeigniter之类的框架结合使用时,它也可以用于处理会话,路由URL以及确定要使用的模板。 Though, I don't believe it can be used to call my REST API to fetch resources (might be wrong here, correct me please if I am). 虽然,我不相信它可以用来调用我的REST API来获取资源(这里可能是错误的,如果我愿意,请纠正我)。

Javascript is client facing but is used only once the webpage has been fetched from the server. Javascript是面向客户端的,但仅在从服务器获取网页后才使用。 AngularJS is great, but from what I've read, it seems it only helps add very dynamic functionality into already rendered static pages. AngularJS很棒,但是据我所读,它似乎仅有助于将非常动态的功能添加到已呈现的静态页面中。

I am really open to any ideas, suggestions, and advice based on your experiences creating client frontends. 根据您创建客户前端的经验,我真的很乐意接受任何想法,建议和意见。 So, back to my original question, how does one structure a REST client frontend, which language is best for this goal, and if which frameworks should one consider to use? 因此,回到我最初的问题,如何构建REST客户端前端,哪种语言最适合此目标,以及是否应该考虑使用哪种框架?

Update 1 更新1

Someone asked whether this client frontend will be run in a browser -- the answer is yes, it will. 有人问这个客户端前端是否将在浏览器中运行-答案是肯定的。 I am trying to build a Twitter-like web client frontend that interacts with a Twitter-like REST API backend. 我正在尝试构建一个类似于Twitter的Web客户端前端,该前端与类似Twitter的REST API后端进行交互。 Basically, everything you see there when you go on Twitter's website. 基本上,您在Twitter网站上看到的所有内容。

REST really, really isn't new. REST确实不是真正的新事物。 It's been a part of HTTP at least as far back as HTTP 1.1 至少早在HTTP 1.1之前,它就已经是HTTP的一部分

Have a look at this question: Backbone.js frontend with RESTful Rails backend? 看一下这个问题: 带有RESTful Rails后端的Backbone.js前端? the top answer lists 20 possible frameworks for building a front end. 最佳答案列出了20个用于构建前端的可能框架。

Since it is a browser frontend I would go with HTML/JavaScript only. 由于它是浏览器前端,因此我只会使用HTML / JavaScript。 No need to use PHP or any server side language IMHO. 无需使用PHP或任何服务器端语言恕我直言。 This has the advantage of being extremely portable. 这具有非常便携的优点。

I would also use a JS framework for that purpose ( the trend nowadays seems to be angular). 我也将为此目的使用JS框架(如今的趋势似乎是有角度的)。

Thanks for your help, everyone. 谢谢大家的帮助。 Found exactly what I was looking for here: http://docs.python-requests.org/en/latest/ 在这里找到我要找的东西: http : //docs.python-requests.org/en/latest/

A nice little library for Python that allows me to basically make calls to a REST backend from within a Django application, which serves as my frontend. 一个不错的Python小库,它使我基本上可以从Django应用程序(作为我的前端)中调用REST后端。

AngularJS will also be used for to make the static pages that Django returns more dynamic. AngularJS也将用于使Django返回的静态页面更具动态性。 Why? 为什么? Because AngularJS by itself can be the complete solution only if your whole site consists of one page. 因为只有整个站点只有一页,AngularJS本身才能成为完整的解决方案。 If you have multiple pages where each one has it's own set of dynamic elements, you need a combination of Django and AngularJS. 如果您有多个页面,每个页面都有自己的一组动态元素,则需要结合使用Django和AngularJS。

Apparently REST is still quite new and it seems there aren't many people that have stumbled upon this very fundamental question like I have. 显然REST还是一个很新的东西,似乎没有多少人像我一样偶然发现这个非常基本的问题。

Once again, thanks! 再次感谢!

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

相关问题 前端应用程序和另一个后端服务使用的REST API的身份验证方法 - Authentication approach for REST API used by frontend app and another backend service Git:关于目录结构,如何分离后端Rest Api和前端应用程序的版本? - Git: How to Separate the Versioning of a Backend Rest Api and the Frontend Application in regards to Directory Structure? REST-Rails API前端 - REST - Rails API Frontend 后端从第三方获取 pdf。 我如何通过 REST api 发送给我的客户? - Backend gets a pdf from a third-party. How can I send it via REST api to my client? 带有REST后端的HTML / javascript客户端 - HTML/javascript client with a REST backend 如何从前端为用户存储 REST api 有效负载? - How to store REST api payload for user from frontend? 如何保护前端免受由来自 REST API 的数据引起的 XSS 攻击? - How to protect the frontend from XSS, caused by data from a REST API? 如何在与 Django Rest API 的反应前端中使用基于权限的函数? - How to use permission based functions in react frontend with Django Rest API? 如何将 Django Rest API 连接到 html CSS JS 前端 - How to connect Django Rest API to a html CSS JS frontend 带有Postgresql的REST API-如何制作最简单的前端接口 - REST API with Postgresql - how to make simplest frontend interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM