Skip to content

POST and Json object examples #64

Answered by scottoffen
Cephy314 asked this question in Q&A
Discussion options

You must be logged in to vote

There are potentially three questions here, so I'm going to address them individually.

  1. How do I create a Post route?
  2. How do I access the request body?
  3. How to I deserialize the payload into an object?

Creating a POST Route

Post routes are created using "Post" as the first parameter in the RestRoute attribute. (You can use any HTTP verb here that you want.)

[RestRoute("Post", "/api/test")]
public async Task TestPost(IHttpContext context)
{
    //Your code here
}

Access The Request Body

You can access the request payload using context.Request.InputStream. Be aware that this stream can only be read once! If you want the payload to be available to future routes, you'll want to add the deseri…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by scottoffen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants