Our client provided me with a REST API that requires a PHP call. However, the documentation accompanying the API is quite scanty, leaving me unsure about how to proceed with calling the service.
I attempted to search for information online, but all I found was a dated Yahoo! tutorial that was no longer valid, and it didn’t cover essential details like headers or in-depth explanations.
I’m wondering if there are any reliable resources available that provide guidance on calling a REST API or offer comprehensive documentation on the topic. Even popular sites like W3Schools seemed to focus primarily on the SOAP method. What other options exist for interacting with REST APIs using PHP?
2
Answers
Any http client written for php such as
curl
orguzzle
can do it. You can even usefile_get_contents
if you enjoy torturing yourself.As for the specifics of what to put in the requests, that can only really come from the API documentation, or published guides/tutorials for that specific API.
I suggest building requests to the API by hand in something like Postman first, so you can be sure you’ve got the structure right. After that, you can try writing some code to do the same job. In fact, Postman can actually auto-generate php code based on the requests you build within it, and it’s usually pretty accurate.
Hope you found the answer. But if you didn’t, try cURL. Because that’s what’s I use.