简体   繁体   English

PHP中的RESTful API,用于以JSON格式输出的脚本

[英]RESTful API in PHP for a script outputting in JSON format

I am a PHP programmer and new to RESTful services. 我是一名PHP程序员,并且是RESTful服务的新手。 I have developed a page which outputs the data in JSON format, based on query parameters (_GET). 我已经开发了一个页面,该页面根据查询参数(_GET)以JSON格式输出数据。 Now I wan't to implement it so that I can call my script with different parameters via REST API. 现在,我不想实现它,以便可以通过REST API使用不同的参数调用脚本。

My question is, how would I go about implementing the API in PHP. 我的问题是,我将如何在PHP中实现API。 Basically, I am developing this so we can integrate the same data that is there on our website in a different interface for our client sites. 基本上,我正在开发它,以便我们可以在不同的客户端站点界面中集成网站上的相同数据。

I already have most of data exposed in JSON format, just need guidance on how to implement the RESTful service for that. 我已经将大多数数据以JSON格式公开,只需要有关如何实现RESTful服务的指南。

are you comfortable with php frameworks? 您对php框架感到满意吗? than you should give a shot to laravel php framework its is really awesome with low learning curve. 比您应该尝试使用laravel php框架要好,它的学习曲线很低。

You can use json_decode of php and you will get array. 您可以使用php的json_decode来获取数组。 You can use decoded array values for further processing. 您可以使用解码后的数组值进行进一步处理。 You can make a http post request or curl alternatively to make a rest request. 您可以发出http发布请求,也可以卷曲以发出休息请求。

Or you could use Slim if you don't like Laravel for some reason. 或者,如果由于某些原因而不喜欢Laravel,则可以使用Slim。 Take a look at https://github.com/victorjonsson/PHP-Rocker it will get you up an running in minutes 看看https://github.com/victorjonsson/PHP-Rocker,它会让您在几分钟内开始运行

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

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