| GET,POST | /url_shortener |
|---|
<?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 url_shortenerResponse implements JsonSerializable
{
public function __construct(
/** @var string|null */
public ?string $tiny_url=null,
/** @var string|null */
public ?string $original_url=null,
/** @var DateTime */
public DateTime $created_date=new DateTime(),
/** @var DateTime|null */
public ?DateTime $expiry_date=null,
/** @var int|null */
public ?int $collision=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['tiny_url'])) $this->tiny_url = $o['tiny_url'];
if (isset($o['original_url'])) $this->original_url = $o['original_url'];
if (isset($o['created_date'])) $this->created_date = JsonConverters::from('DateTime', $o['created_date']);
if (isset($o['expiry_date'])) $this->expiry_date = JsonConverters::from('DateTime', $o['expiry_date']);
if (isset($o['collision'])) $this->collision = $o['collision'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->tiny_url)) $o['tiny_url'] = $this->tiny_url;
if (isset($this->original_url)) $o['original_url'] = $this->original_url;
if (isset($this->created_date)) $o['created_date'] = JsonConverters::to('DateTime', $this->created_date);
if (isset($this->expiry_date)) $o['expiry_date'] = JsonConverters::to('DateTime', $this->expiry_date);
if (isset($this->collision)) $o['collision'] = $this->collision;
return empty($o) ? new class(){} : $o;
}
}
enum operationType : string
{
case NoOperation = '0x4E71';
case ShortenUrl = 'ShortenUrl';
case GetOriginalUrl = 'GetOriginalUrl';
case RedirectUrl = 'RedirectUrl';
}
class url_shortener implements JsonSerializable
{
public function __construct(
/** @description operation type */
// @ApiMember(DataType="string", Description="operation type", IsRequired=true, Name="operation", ParameterType="body")
/** @var operationType|null */
public ?operationType $operation=null,
/** @description url */
// @ApiMember(DataType="string", Description="url", IsRequired=true, Name="url", ParameterType="body")
/** @var string */
public string $url='',
/** @description days to expire */
// @ApiMember(DataType="string", Description="days to expire", Name="days", ParameterType="body")
/** @var float|null */
public ?float $days=null
) {
}
/** @throws Exception */
public function fromMap($o): void {
if (isset($o['operation'])) $this->operation = JsonConverters::from('operationType', $o['operation']);
if (isset($o['url'])) $this->url = $o['url'];
if (isset($o['days'])) $this->days = $o['days'];
}
/** @throws Exception */
public function jsonSerialize(): mixed
{
$o = [];
if (isset($this->operation)) $o['operation'] = JsonConverters::to('operationType', $this->operation);
if (isset($this->url)) $o['url'] = $this->url;
if (isset($this->days)) $o['days'] = $this->days;
return empty($o) ? new class(){} : $o;
}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json
To embed the response in a jsonp callback, append ?callback=myCallback
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /url_shortener HTTP/1.1
Host: milliet.io
Accept: application/json
Content-Type: application/json
Content-Length: length
{"operation":"0x4E71","url":"String","days":0}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length
{"tiny_url":"String","original_url":"String","created_date":"0001-01-01T00:00:00.0000000","expiry_date":"0001-01-01T00:00:00.0000000","collision":0}