0

I want to create a Restful Web service in Php which returns json format. So that Can be consumed from other mobile and Web Applications.

I wanted to Create a Get Method.

piet.t
11.9k21 gold badges45 silver badges56 bronze badges
asked May 29, 2018 at 4:40
1
  • 1
    That's a great idea, but could you ask a question about a specific problem? Commented May 29, 2018 at 4:51

3 Answers 3

1
// index.php
<?php 
 header('Content-type: application/json'); 
 echo '{"status":"restful"}'; 
?>

Put on your webserver and bam! I would argue that you now have a VERY restful web service that can be consumed from other mobile and web applications. In json format nonetheless.

Sorry, I was trying to be cheeky. But if this worked for you, then you might as well serve a file.json with { "something":"somethingelse" } directly from your webserver. No PHP needed. At least not for GET requests.

You can even put it in the same folder as your webapp and do a $.get('file.json') or $http.get or axios.get or whatever get floats your boat.

answered May 29, 2018 at 6:53
0

To send a json response you have to serialize the content. In order for doing it you can use jms/serializer, here you can find the documentation for this library. I hope it helps

answered May 29, 2018 at 4:54
0

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and RESTful APIs. If you want to go Vanilla try this tutorial: Building a Simple Web API with Vanilla PHP

answered May 29, 2018 at 6:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.