Call a REST API in PHP

You can access any REST API with PHPs cURL Extension. However, the API Documentation (Methods, Parameters etc.) must be provided by your Client! Example: // Method: POST, PUT, GET etc // Data: array(“param” => “value”) ==> index.php?param=value function CallAPI($method, $url, $data = false) { $curl = curl_init(); switch ($method) { case “POST”: curl_setopt($curl, CURLOPT_POST, 1); … Read more

What are best practices for REST nested resources?

I’ve tried both design strategies – nested and non-nested endpoints. I’ve found that: if the nested resource has a primary key and you don’t have its parent primary key, the nested structure requires you to get it, even though the system doesn’t actually require it. nested endpoints typically require redundant endpoints. In other words, you … Read more

REST / SOAP endpoints for a WCF service

You can expose the service in two different endpoints. the SOAP one can use the binding that support SOAP e.g. basicHttpBinding, the RESTful one can use the webHttpBinding. I assume your REST service will be in JSON, in that case, you need to configure the two endpoints with the following behaviour configuration <endpointBehaviors> <behavior name=”jsonBehavior”> … Read more

What’s an appropriate HTTP status code to return by a REST API service for a validation failure?

If “validation failure” means that there is some client error in the request, then use HTTP 400 (Bad Request). For instance if the URI is supposed to have an ISO-8601 date and you find that it’s in the wrong format or refers to February 31st, then you would return an HTTP 400. Ditto if you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)