Skip to content

How to accept requests that do not use json encoding? #557

@khanetor

Description

@khanetor

I have a request like this

POST /api/?method=some-method&encrypted=true HTTP/1.1
Host: axis.com
Content-Type: application/x-www-form-urlencoded
Content-Length: NNN
some_long_string_without_double_quotes_here

Due to the origin of this request, nothing can be done to change it to use json content-type. Regardless, I have a schema like this

@simpleRestJson
service CameraService {
    version: "1.0.0",
    operations: [Report]
}

@http(method: "POST", uri: "/api", code: 200)
operation Report {
    input: CameraQuery,
    output: AxisTimestamp
}

structure CameraQuery {
    @required
    @httpQuery("method")
    method: String,

    @required
    @httpQuery("encrypted")
    encrypted: Boolean,

    @required
    @httpPayload
    payload: String
}

When I submit the request above with double quotes around the body, then it works. But if I remove the double quotes, then I get 500, as expected because the body does not confirm to json format. I then tried changing the payload to Blob instead of String, and I get 500 error regardless.

How should I handle this case?

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