Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST body parser #10

Closed
dsseng opened this issue Feb 4, 2019 · 4 comments
Closed

POST body parser #10

dsseng opened this issue Feb 4, 2019 · 4 comments

Comments

@dsseng
Copy link

dsseng commented Feb 4, 2019

Implement something like express' bodyParsermiddleware

@kitsonk
Copy link
Collaborator

kitsonk commented Feb 4, 2019

It is already implemented in the context.request.body(). It handles JSON, urlencoded, and text automatically. It will handle multipart in the future.

From the README:

  • .body()

The method resolves to a parsed version of the request body. Currently oak
supports request body types of JSON, text and URL encoded form data. If the
content type of the request is not supported, the request will be rejected
with a 415 HTTP Error.

If the content type is supported, the method resolves with an object which
contains a type property set to "json", "text", "form", or
"undefined" and a value property set with the parsed value of the
property. For JSON it will be the parsed value of the JSON string. For text,
it will simply be a string and for a form, it will be an instance of
URLSearchParams. For an undefined body, the value will be undefined.

For more advanced use cases of the body, the original server request is
available and contains a .body() and .bodyStream() methods.

@kitsonk kitsonk closed this as completed Feb 4, 2019
@bobwatcherx
Copy link

How to
Get body from json and urlencoded

I use .body({type:'form'}) . This work for content type form but not work for content type json?
My console request body is null value ?
Give me example code request body in OAK?

@bobwatcherx
Copy link

Is there body-parser in OAK?
Like body-parser in express Js?

@dotku
Copy link

dotku commented Aug 30, 2024

I got context.request.body undefined, why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants