Handling a batch REST request in PHP -


for php application integrating rest service capable of receiving multiple nested http requests @ once. identical google calendar api: https://developers.google.com/google-apps/calendar/batch

however, not sure best way parse single request multiple requests. request server (from google example) this:

post /batch http/1.1 authorization: bearer your_auth_token host: host content-type: multipart/mixed; boundary=batch_foobarbaz content-length: total_content_length  --batch_foobarbaz content-type: application/http content-id: <item1:12930812@barnyard.example.com>  /farm/v1/animals/pony  --batch_foobarbaz content-type: application/http content-id: <item2:12930812@barnyard.example.com>  put /farm/v1/animals/sheep content-type: application/json content-length: part_content_length if-match: "etag/sheep"  {     "animalname": "sheep",     "animalage": "5"     "peltcolor": "green", }  --batch_foobarbaz 

the top section (above --batch_foobarbaz) should available in $_server presume. nested requests cannot use that.

my current action plan be:

  • create request class properties each header
  • create request parsing class parses each single request object
  • for /batch requests wrapper used splits batch multiple smaller request objects, feeding them extracted nested requests.
  • for normal/single requests populate request data headers. both nested , single requests handled same through request parsing class.

the splitting of request done using explode() on boundary. then? parse each section using regular expressions every key:value? , expect payload wrapped in newlines? or there function / class available me?

any suggestions on how tackle appreciated. response multipart/mixed message responses per request. way each single request still use rest principles.

1) if absolutely insist on multipart/mixed style following old stack overflow articles may useful:

2) if can influence rest api design easier both (the parser) , users if you'd support 1 json batch data on input. rest api supposed simplify things, not make them more complicated.

for examples e.g. here (some google results "batch rest api" query):


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -