Skip to content

How to handle POST requests with JSON payload in the body? #11

Open
@s4m13337

Description

@s4m13337

Here is simple example of what I am doing:

APIFunction[
    {},
    If[HTTPRequestData["Method"] === "GET",
        "400 Bad Request",
        ExportForm[HTTPRequestData["Body"], "JSON"]
    ]&
]

I pass the following JSON object to the endpoint:

{
    x: 1,
    y: 2,
    z: 3
}

I have tried using postman, insomnia and fetch function in javascript to send the payload. All of them complain Expression "None" cannot be exported as JSON. Upon closer inspection, I found that HTTPRequestData["Body"] remains None for some reason.

What would be the best way to deal with JSON payloads in POST requests? It may be helpful to know that the above function works fine when deployed in Wolfram Application Server.

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