Hello folks, hope you are doing good. In one of my recent project, I get a chance to create RESTClient a debugger for RESTful web services using PHP.
In today’s tutorial, I will share very useful things with you. After this tutorial, you will able to create a restCliient using PHP.
In order to create RestClient using PHP, first you have to include the httpful.phar
file to perform the request and receive Http requests. Download the complete code from the link included at the end of this tutorial. Create a index.php
page and copy paste below code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
< ?php /** * Created by Prem Tiwari. * User: prem.tiwari * Date: 2/16/2017 * Time: 4:08 PM */ // Point to the httpful.phar file path include('./httpful.phar'); //set header content type as json header('Content-Type: application/json'); //api url $uri = "http://localhost:3000/api/v1/tokenize"; //set headers $header['merchantID'] = "test"; $header['Content-Type'] = "application/json"; //set the request data $body['cardNumber'] = "xxxxxxxxxxxx1111"; $body['securityCode'] = "xxx"; $body['cardIssuer'] = "Prem Tiwari"; $body['expirationDate'] = "11/2020"; $response = \Httpful\Request::post($uri) ->sendsJson() ->addHeaders($header) ->body($body) ->send(); //create response $res['success'] = $response->body->success; $res['token'] = $response->body->token; echo json_encode($res); ?> |
If you still need any help to create RestClient, then feel free to add your comments in below comment section. Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool tutorials.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: best php tutorials, json and php tutorial, php beginners, php rest api client, php rest client, php rest client example, php tutorials for beginners, rest client php, rest client php example, RestClient using php