swifter icon indicating copy to clipboard operation
swifter copied to clipboard

Response Body for 201 and 500

Open ryantstone opened this issue 7 years ago • 4 comments

Is there currently not a way to respond with JSON for 201 & 500 responses? I'm mocking a Rails server that does respond to those statuses with content.

ryantstone avatar Jun 24 '18 13:06 ryantstone

404 as well.

Macarse avatar Jul 27 '18 14:07 Macarse

Any update on this?

sonic555gr avatar Mar 06 '19 10:03 sonic555gr

would be great to have 207(multiStatus) status code response with JSON, too.

gitMartynas avatar Jul 31 '19 14:07 gitMartynas

I had to create my own response code with a custom body. This might be of help

extension HttpResponse {
    static func NotFoundResponseWithBody(body: AnyObject) -> HttpResponse {
        let data = try! JSONSerialization.data(withJSONObject: body)
        return HttpResponse.raw(404, "Not found", nil, { (writer) in
            try writer.write(data)
        })
    }
}

sonic555gr avatar Jul 31 '19 15:07 sonic555gr