Jump to content

Http Rest Api Help!


Dynamix

Recommended Posts

I have a company that needs php tweaking. (My previous programmer couldn't be found anymore)

The client e-mailed me this

"Basically what we need is for you to provide us with an http rest API where we will provide the tracking code and in return you will return to us a JSON object with the status of the delivery

 

As an example:

 

TRACKING CODE: ABCDEFGHIJ

URL:

METHOD: GET

RESPONSE: {"status":2}

 

where 2 is the code for the status shipment which is defined by

 

1 - GOOD

2 - BETTER

3 - BEST"

How and where do I place this? What's "HTTP REST API" and "return to us a JSON object"

 

It's all gibberish to me! Some web guru answer me pls?:)

 

 

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/269895-http-rest-api-help/
Share on other sites

Just setup a script that gets a code, checks it and echoes out the status of it.

 

<?php


/**
* http://fastrak.com/track.php?code=ABCDEFGHIJ
*/


// get the CODE from the GET varaible
$code = isset($_GET["code"]) ? $_GET["code"] : "";


// to whatever you need to do to check if that $code is valid
// if its not valid return an 404 error


// then get the status of that code


$return = array(
   "status" => "get this status from the database or whatever",
);


// and echo that out
echo json_encode($return);


?>

Link to comment
https://forums.phpfreaks.com/topic/269895-http-rest-api-help/#findComment-1388101
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.