-1

My client has got some RESTful services written in ASP.net and front end code in PHP. He is providing me DTO classes and API url. Can anyone help me how to call these API services from PHP? I do not know how to make use of DTO classes in PHP

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Dee
  • 49
  • 5

1 Answers1

1

The DTO classes will just specify the contract. I would imagine they will map to JSON objects returned by the service (although you will want to check the serialization format).

You should look into deserializing JSON to PHP objects: http://php.net/manual/en/function.json-decode.php

Something like

$url="http://www.website.com/api/object/1";
$json = file_get_contents($url);
$data = json_decode($json);

It doesnt seem trivial to decode to a specific class but you could declare a class for each DTO in PHP and instantiate the appropriate class from the client code and populate it with the data on the dynamic object that json_decode() returns.

Tom Elmore
  • 1,980
  • 15
  • 20