3

I know that the data is passed through HTTP, but I'm not sure if I should be passing data through HTTP headers, or HTTP bodies. Which one is the convention for APIs?

Also, theoretically using PHP, which would be easier to process? Based on what I know, using headers seems to be the easiest method.

POST body

POST /api/v1/test_params.json HTTP/1.1
Host: rollrbla.de
Content-Length: 59
X-Target-URI: http://rollrbla.de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Connection: Keep-Alive

Test-Parameter-1=Test-value-1&Test-Parameter-2=Test-Value-2

POST header

POST /api/v1/test_params.json HTTP/1.1
Test-Parameter-2: Test-Value-2
Host: rollrbla.de
Test-Parameter-1: Test-Value-1
Content-Length: 0
X-Target-URI: http://rollrbla.de
Connection: Keep-Alive

Overall, what would be the best way to process this data, and what is the convention?

12

The body.

Headers are supposed to describe the request, not encapsulate its payload.

Headers are meta-data.

2

I've looked at what a request looks like using body parameters and header parameters, and also some PHP examples (thanks to @RobertHarvey) and I've concluded that body parameters are the best way to go, as they do not require any special functions to read in PHP. I was just unsure of what they were, but now I understand completely.

POST Body

POST /api/v1/test_params.json HTTP/1.1
Host: rollrbla.de
Content-Length: 59
X-Target-URI: http://rollrbla.de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Connection: Keep-Alive

Test-Parameter-1=Test-value-1&Test-Parameter-2=Test-Value-2

... is the best way to go. Thanks to everybody who helped me reach this conclusion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.