如何使用PHP的宁静API为中心的设计的内部,而不是与HTTP请求 [英] How to use a php restful api-centric design internal instead of with http request

查看:127
本文介绍了如何使用PHP的宁静API为中心的设计的内部,而不是与HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个PHP宁静的API为中心的Web应用程序/网站,我有数据/ API,它会从我的前端code调用。除了使HTTP /卷曲请求,每次我打开一个网页,我能为使用框架喜欢苗条的内部API调用做电话?

I want to create a php restful api-centric web application/website where I have the data/api that gets called from my front end code. Besides making HTTP/curl request calls each time I load a page, what can I do for internal API calls using frameworks like slim?

我不知道的一种方式,包括供内部使用的API在我的前端code,仍然保持它拆开。

I'm not sure of a way to include the api for internal use in my front end code and still keep it apart.

我的想法是这样的:

"example.com/api/story/todays-weather/"
pulls in the json formatted story with a http request with curl or Ajax

而是我可以做这样的事情:

But instead could I do something like:

require("/api/internal.php");
$uri = "/story/todays-weather/";
$call = api::getStory($uri);
$result = json_decode($call);
.....

我在朝着正确的方向还是我的方法了吗?

Am I headed in the right direction or am I way off?

中的API和前code是在同一个云盒子(亚马逊E2 / LAMP)和我刨使用的memcached的API。

The api and front code are on the same cloud box (Amazon E2/LAMP) and I am planing on using memcached for the api.

推荐答案

所以,你婉有你的API和前端的东西之间​​的code分离?你可以使用超薄框架要做到这一点,所以你将有一个简单的维护code。修身框架是很容易写的模型,也prepare数据以备将来使用,甚至进行缓存。

So you wan to have a code separation between your API and front-end stuff ? You could use Slim Framework to do that so you will have an easy maintainable code. Slim Framework is very easy to write models and also prepare the data for future use and even cache it.

也看看PHP的RESTful API框架的这个名单:
http://davss.com/tech/php-rest-api-frameworks/

Also have a look at this list of PHP RESTful API Frameworks: http://davss.com/tech/php-rest-api-frameworks/

您也可以采取不同的方法,并使用前端机型做既code分离,并有一个很好的code结构。对于我建议 Backbone.js的这将提供一些不错的键 - 值绑定和事件处理前端$ C $角

You could also take a different approach and use front-end models to do both the code separation and have a nice code structure. For that I recommend Backbone.js which will provide some nice key-value bindings and event handling for your front-end code.

这篇关于如何使用PHP的宁静API为中心的设计的内部,而不是与HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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