[英]Webservice for mobile Application using REST Service in PHP
I have to create a webservice for mobile application(IPhone and Android) in Rest Service. 我必须在Rest Service中为移动应用程序(iPhone和Android)创建Web服务。 This Application is based one E-Publishing.
该应用程序基于一种电子出版。 I try some REST service based on SLIM .
我尝试一些基于SLIM的REST服务。 I can able to add a data into db and also retrieve the data from DB.
我可以向db中添加数据,也可以从DB中检索数据。
I use the following link to develop REST Service 我使用以下链接来开发REST服务
http://phpmaster.com/writing-a-restful-web-service-with-slim/
I am able to add a new data through form in html but i want to use url to add a data. 我能够通过html中的表单添加新数据,但我想使用url添加数据。 but i cant.
但是我不能。 here is the code i used
这是我使用的代码
<form action="http://localhost/samples/Restfull/samp5/index.php/custom" method="POST">
<input type="hidden" name="_METHOD" value="POST">
Name: <input type="text" name="Customer_Name"><br>
Mobile: <input type="text" name="Customer_Mobile"><br>
Email: <input type="text" name="Customer_Email"><br>
Address: <textarea name="Customer_Address"></textarea>
<br>
<input type="submit" value="Submit">
</form>
When i try through this form , the operation is successfully done. 当我尝试通过此表单时,操作成功完成。 But i want to make that as web service.
但我想将其作为Web服务。 I try to add data through url but failed, at the same time Delete or get data by using join queries also not working.
我尝试通过url添加数据,但同时失败,同时使用联接查询删除或获取数据也不起作用。
I retrieve data from Db by using following function 我通过使用以下功能从Db检索数据
$app->get("/custom/:id", function ($id) use ($app, $db) {
$app->response()->header("Content-Type", "application/json");
$custom = $db->Registration()->where("Registration_Id", $id);
if ($data = $custom->fetch()) {
echo json_encode(array(
"custom_Name" => $data["Customer_Name"],
"custom_Mobile" => $data["Customer_Mobile"],
"custom_Email" => $data["Customer_Email"],
"custom_Address" => $data["Customer_Address"]
));
}
else{
echo json_encode(array(
"status" => false,
"message" => " $id does not exist"
));
}
});
This also works well. 这也很好。
Is any other way or good samples available. 有其他可用的方法或好的样本吗? Not only in Slim.
不仅在Slim中。 I need to integrate REST Service.
我需要集成REST服务。 Please suggest on this.
请对此提出建议。
Thanks in advance. 提前致谢。
Ok, I think this is where you need to get started :) 好的,我认为这是您需要开始的地方:)
If you are going to use the url to set data then you are have to use HTTP get method. 如果要使用url设置数据,则必须使用HTTP get方法。 If you use java to develop the restful service I suggest you to use Jersey (JAX-RS (JSR 311) Reference Implementation for building RESTful Web services.)
如果您使用Java开发静态服务,则建议您使用Jersey (JAX-RS(JSR 311)参考实现,用于构建RESTful Web服务。)
At your project service you can define methods with HTTP get method 在您的项目服务中,您可以使用HTTP get方法定义方法
@Stateless
@Path("/basepath")
@javax.ws.rs.Produces("application/json")
@javax.ws.rs.Consume("application/json")
public class RestService {
@Path("/{index}")
public String M(@PathParam("index") String index){
//you can use index value here
}
}
so what ever after the "basepath/" in your URL, you can use that value. 因此,在您网址中的“ basepath /”之后,您都可以使用该值。
If you want to get started with restful services, it is very easy to do with Netbeans. 如果您想开始使用宁静的服务,那么使用Netbeans非常容易。 here are some links that might help you.
这是一些可能对您有帮助的链接。
netbeans.org/kb/docs/websvc/rest.html netbeans.org/kb/docs/websvc/rest.html
netbeans.org/kb/docs/websvc/intro-ws.html netbeans.org/kb/docs/websvc/intro-ws.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.