| GET | /2.0/address/{Postcode} | ||
|---|---|---|---|
| GET | /2.0/address/{Postcode}/{HouseNo} |
<?php namespace dtos;
use DateTime;
use Exception;
use DateInterval;
use JsonSerializable;
use ServiceStack\{IReturn,IReturnVoid,IGet,IPost,IPut,IDelete,IPatch,IMeta,IHasSessionId,IHasBearerToken,IHasVersion};
use ServiceStack\{ICrud,ICreateDb,IUpdateDb,IPatchDb,IDeleteDb,ISaveDb,AuditBase,QueryDb,QueryDb2,QueryData,QueryData2,QueryResponse};
use ServiceStack\{ResponseStatus,ResponseError,EmptyResponse,IdResponse,ArrayList,KeyValuePair2,StringResponse,StringsResponse,Tuple2,Tuple3,ByteArray};
use ServiceStack\{JsonConverters,Returns,TypeContext};
// @DataContract(Name="Address", Namespace="http://schemas.datacontract.org/2004/07/PostcodeLookupService")
class Address implements JsonSerializable
{
public function __construct(
// @DataMember
/** @var string|null */
public ?string $County=null,
// @DataMember
/** @var int */
public int $Id=0,
// @DataMember
/** @var string|null */
public ?string $Locality=null,
// @DataMember
/** @var string|null */
public ?string $Organisation=null,
// @DataMember
/** @var string|null */
public ?string $Postcode=null,
// @DataMember
/** @var string|null */
public ?string $Property=null,
// @DataMember
/** @var int */
public int $RAPPPremiseId=0,
// @DataMember
/** @var string|null */
public ?string $Street=null,
// @DataMember
/** @var string|null */
public ?string $Town=null,
// @DataMember
/** @var string|null */
public ?string $FullAddress=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['County'])) $this->County = $o['County'];
if (isset($o['Id'])) $this->Id = $o['Id'];
if (isset($o['Locality'])) $this->Locality = $o['Locality'];
if (isset($o['Organisation'])) $this->Organisation = $o['Organisation'];
if (isset($o['Postcode'])) $this->Postcode = $o['Postcode'];
if (isset($o['Property'])) $this->Property = $o['Property'];
if (isset($o['RAPPPremiseId'])) $this->RAPPPremiseId = $o['RAPPPremiseId'];
if (isset($o['Street'])) $this->Street = $o['Street'];
if (isset($o['Town'])) $this->Town = $o['Town'];
if (isset($o['FullAddress'])) $this->FullAddress = $o['FullAddress'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->County)) $o['County'] = $this->County;
if (isset($this->Id)) $o['Id'] = $this->Id;
if (isset($this->Locality)) $o['Locality'] = $this->Locality;
if (isset($this->Organisation)) $o['Organisation'] = $this->Organisation;
if (isset($this->Postcode)) $o['Postcode'] = $this->Postcode;
if (isset($this->Property)) $o['Property'] = $this->Property;
if (isset($this->RAPPPremiseId)) $o['RAPPPremiseId'] = $this->RAPPPremiseId;
if (isset($this->Street)) $o['Street'] = $this->Street;
if (isset($this->Town)) $o['Town'] = $this->Town;
if (isset($this->FullAddress)) $o['FullAddress'] = $this->FullAddress;
return empty($o) ? new class(){} : $o;
}
}
// @DataContract(Name="LookupResult", Namespace="http://schemas.datacontract.org/2004/07/PostcodeLookupService")
class LookupResult implements JsonSerializable
{
public function __construct(
// @DataMember
/** @var Address[]|null */
public ?array $Addresses=null,
// @DataMember
/** @var string|null */
public ?string $errormsg=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['Addresses'])) $this->Addresses = JsonConverters::fromArray('Address', $o['Addresses']);
if (isset($o['errormsg'])) $this->errormsg = $o['errormsg'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->Addresses)) $o['Addresses'] = JsonConverters::toArray('Address', $this->Addresses);
if (isset($this->errormsg)) $o['errormsg'] = $this->errormsg;
return empty($o) ? new class(){} : $o;
}
}
class AddressRequest implements IHasVersion, JsonSerializable
{
public function __construct(
/** @var int */
public int $Version=0,
/** @description Using a Postcode to return addresses. */
// @ApiMember(DataType="string", Description="Using a Postcode to return addresses.", IsRequired=true, Name="Postcode", ParameterType="path")
/** @var string */
public string $Postcode='',
/** @description Optional input value to limit the return data to a specific address. */
// @ApiMember(DataType="string", Description="Optional input value to limit the return data to a specific address.", Name="House Name or Number", ParameterType="path")
/** @var string|null */
public ?string $HouseNo=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['Version'])) $this->Version = $o['Version'];
if (isset($o['Postcode'])) $this->Postcode = $o['Postcode'];
if (isset($o['HouseNo'])) $this->HouseNo = $o['HouseNo'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->Version)) $o['Version'] = $this->Version;
if (isset($this->Postcode)) $o['Postcode'] = $this->Postcode;
if (isset($this->HouseNo)) $o['HouseNo'] = $this->HouseNo;
return empty($o) ? new class(){} : $o;
}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .csv suffix or ?format=csv
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
GET /2.0/address/{Postcode} HTTP/1.1
Host: webservices.mbukdatabase.co.uk
Accept: text/csv
HTTP/1.1 200 OK
Content-Type: text/csv
Content-Length: length
{"Addresses":[{"County":"String","Id":0,"Locality":"String","Organisation":"String","Postcode":"String","Property":"String","RAPPPremiseId":0,"Street":"String","Town":"String","FullAddress":"String, String, String, String, String, String"}],"errormsg":"String"}