I am building an API using JSON to offer to our customers so they can check inventory levels on our product(s). Everything works fine when testing 1 product. My question is, what is the best method to receive a $_GET request that could possibly be 1 product or up to 5k products? Would those multiple products get built into the request URL? Or, would the requesting party loop thru and call the API with 1 products at a time?

I've worked with UPS using XML & cURL where I set CURLOPT_POSTFIELDS that contains multiple params but I am not sure how to build the request using the method I've created.

Here is a basic example of what my request looks like:

//user request
$url = 'http://php.mybizurl.com/public/api/api_get_data.php';
$api = 'api_inventory_check';
$key = '12341234';
$fmt = 'json';

//api_get_data.php gets the URL params, query's the DB, json_encode & outputs

$result = file_get_contents($url . '?api=' . $api . '&num=' . $key . '&format=' . $fmt);



Hopefully that makes some sense. I appreciate any insight.

THanks,
J

    The HTTP 1/1 specification says, in part:

    https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2.1 wrote:

    Note: Servers ought to be cautious about depending on URI lengths above 255 bytes, because some older client or proxy implementations might not properly support these lengths.

    That would certainly set a limit. A quick search indicates that most modern browsers tend to crap out at 2KB, 4KB, or 8KB (IE, Opera, FFox, respectively) on either GET or POST requests.

    I'd suggest your server tech stack might also have some bearing on this. Something light & fast like nGinX I would certainly think capable of handling a ton of small requests.

      Thanks for the reply. Would you recommend I use $_POST. I guess I am just struggling to figure out how the request would look / be received if it has 2k products they're querying? Would the body would contain all the data and I would receive it as an array... get the DB data and return as XML/JSON?

        I posted on here to early w/o researching enough. Using cURL I see how to pass the parameters. Will mark resolved. Thanks.

          actually...I'm not sure how to Mark this Resolved. I don't see that option under Thread Tools.

            Write a Reply...