Luracast / Restler

Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and/or RESTful API
http://luracast.com/products/restler/
GNU Lesser General Public License v2.1
1.36k stars 315 forks source link

Support for "text/plain" format? #604

Closed lathspell closed 6 years ago

lathspell commented 6 years ago

Why is there no text/plain format i.e. Format/TextPlainFormat.php class?

lathspell commented 6 years ago

Meanwhile this seems to work:

Scope::set("TextPlainFormat", new TextPlainFormat());

$restler = new Restler();
$restler->setOverridingFormats('TextPlainFormat'); 
...

with:

<?php

namespace netcologne\ocms\apex360;

use Luracast\Restler\Format\Format;

class TextPlainFormat extends Format
{
    const MIME = 'text/plain';

    public function encode($data, $humanReadable = false)
    {
        return $data;
    }

    public function decode($data)
    {
        return $data;
    }
}

and

   ...
     * @url GET /ping
     * @format TextPlainFormat
     * @return string "pong"
     */
    public function ping()
   ...
JoyceBabu commented 6 years ago

If you are planning to use text/plain as an input format, you should add isReadable too

class TextPlainFormat extends Format
{
    const MIME = 'text/plain';

    public function encode($data, $humanReadable = false)
    {
        return $data;
    }

    public function decode($data)
    {
        return $data;
    }

    /**
     * @return bool false as text/plain format is write only
     */
    public function isReadable()
    {
        return false;
    }
}