Test

<back to all web services

EchoTypes

The following routes are available for this service:
All Verbs/echo/types
<?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};


class EchoTypes implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $byte=0,
        /** @var int */
        public int $short=0,
        /** @var int */
        public int $int=0,
        /** @var int */
        public int $long=0,
        /** @var int */
        public int $uShort=0,
        /** @var int */
        public int $uInt=0,
        /** @var int */
        public int $uLong=0,
        /** @var float */
        public float $float=0.0,
        /** @var float */
        public float $double=0.0,
        /** @var float */
        public float $decimal=0.0,
        /** @var string|null */
        public ?string $string=null,
        /** @var DateTime */
        public DateTime $dateTime=new DateTime(),
        /** @var DateInterval|null */
        public ?DateInterval $timeSpan=null,
        /** @var DateTime */
        public DateTime $dateTimeOffset=new DateTime(),
        /** @var string */
        public string $guid='',
        /** @var string */
        public string $char=''
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['byte'])) $this->byte = $o['byte'];
        if (isset($o['short'])) $this->short = $o['short'];
        if (isset($o['int'])) $this->int = $o['int'];
        if (isset($o['long'])) $this->long = $o['long'];
        if (isset($o['uShort'])) $this->uShort = $o['uShort'];
        if (isset($o['uInt'])) $this->uInt = $o['uInt'];
        if (isset($o['uLong'])) $this->uLong = $o['uLong'];
        if (isset($o['float'])) $this->float = $o['float'];
        if (isset($o['double'])) $this->double = $o['double'];
        if (isset($o['decimal'])) $this->decimal = $o['decimal'];
        if (isset($o['string'])) $this->string = $o['string'];
        if (isset($o['dateTime'])) $this->dateTime = JsonConverters::from('DateTime', $o['dateTime']);
        if (isset($o['timeSpan'])) $this->timeSpan = JsonConverters::from('DateInterval', $o['timeSpan']);
        if (isset($o['dateTimeOffset'])) $this->dateTimeOffset = JsonConverters::from('DateTime', $o['dateTimeOffset']);
        if (isset($o['guid'])) $this->guid = $o['guid'];
        if (isset($o['char'])) $this->char = $o['char'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->byte)) $o['byte'] = $this->byte;
        if (isset($this->short)) $o['short'] = $this->short;
        if (isset($this->int)) $o['int'] = $this->int;
        if (isset($this->long)) $o['long'] = $this->long;
        if (isset($this->uShort)) $o['uShort'] = $this->uShort;
        if (isset($this->uInt)) $o['uInt'] = $this->uInt;
        if (isset($this->uLong)) $o['uLong'] = $this->uLong;
        if (isset($this->float)) $o['float'] = $this->float;
        if (isset($this->double)) $o['double'] = $this->double;
        if (isset($this->decimal)) $o['decimal'] = $this->decimal;
        if (isset($this->string)) $o['string'] = $this->string;
        if (isset($this->dateTime)) $o['dateTime'] = JsonConverters::to('DateTime', $this->dateTime);
        if (isset($this->timeSpan)) $o['timeSpan'] = JsonConverters::to('DateInterval', $this->timeSpan);
        if (isset($this->dateTimeOffset)) $o['dateTimeOffset'] = JsonConverters::to('DateTime', $this->dateTimeOffset);
        if (isset($this->guid)) $o['guid'] = $this->guid;
        if (isset($this->char)) $o['char'] = $this->char;
        return empty($o) ? new class(){} : $o;
    }
}

PHP EchoTypes DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .xml suffix or ?format=xml

HTTP + XML

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /echo/types HTTP/1.1 
Host: test.servicestack.net 
Accept: application/xml
Content-Type: application/xml
Content-Length: length

<EchoTypes xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Test.ServiceInterface">
  <Byte>0</Byte>
  <Char>0</Char>
  <DateTime>0001-01-01T00:00:00</DateTime>
  <DateTimeOffset xmlns:d2p1="http://schemas.datacontract.org/2004/07/System">
    <d2p1:DateTime>0001-01-01T00:00:00Z</d2p1:DateTime>
    <d2p1:OffsetMinutes>0</d2p1:OffsetMinutes>
  </DateTimeOffset>
  <Decimal>0</Decimal>
  <Double>0</Double>
  <Float>0</Float>
  <Guid>00000000-0000-0000-0000-000000000000</Guid>
  <Int>0</Int>
  <Long>0</Long>
  <Short>0</Short>
  <String>String</String>
  <TimeSpan>PT0S</TimeSpan>
  <UInt>0</UInt>
  <ULong>0</ULong>
  <UShort>0</UShort>
</EchoTypes>
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: length

<EchoTypes xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Test.ServiceInterface">
  <Byte>0</Byte>
  <Char>0</Char>
  <DateTime>0001-01-01T00:00:00</DateTime>
  <DateTimeOffset xmlns:d2p1="http://schemas.datacontract.org/2004/07/System">
    <d2p1:DateTime>0001-01-01T00:00:00Z</d2p1:DateTime>
    <d2p1:OffsetMinutes>0</d2p1:OffsetMinutes>
  </DateTimeOffset>
  <Decimal>0</Decimal>
  <Double>0</Double>
  <Float>0</Float>
  <Guid>00000000-0000-0000-0000-000000000000</Guid>
  <Int>0</Int>
  <Long>0</Long>
  <Short>0</Short>
  <String>String</String>
  <TimeSpan>PT0S</TimeSpan>
  <UInt>0</UInt>
  <ULong>0</ULong>
  <UShort>0</UShort>
</EchoTypes>