Skip to content

Documentation wrong about returning string from REST endpoints? #2827

@vpanteleev-sym

Description

@vpanteleev-sym

https://vibed.org/api/vibe.web.rest/ says:

Custom serialization can be achieved by defining JSON or string parameters/return values together with the appropriate @bodyParam annotations.

and:

The most basic interface that can be defined is as follows:

@path("/api/")
interface APIRoot {
    string get();
}

This defines an API that has a single endpoint, 'GET /api/'. So if the server is found at http://api.example.com, performing a GET request to http://api.example.com/api/ will call the get() method and send its return value verbatim as the response body.

(ehpmasis added)

However, the following endpoint:

@path("/test")
interface ITestController {
  string get();
}

final class TestController : ITestController {
  override string get() {
    return "hello";
  }
}

actually returns "hello", and not hello, meaning that the string was serialized to JSON as usual.

I also couldn't find any trace of this feature in the code. The return type is passed to ResultSerializersT here, falling back by default to DefaultSerializerT, which only contains the JSON serializer.

I was going to file an issue to suggest that const(ubyte)[] is added to the list of types returned verbatim, but it doesn't look like even strings work here. (However, looks like for now this can be achieved by returning a Vibe input stream object.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions