Fasthttp: How to read from a json request

Created on 6 Jan 2018  路  2Comments  路  Source: valyala/fasthttp

You wrote in README:

r.Body -> ctx.PostBody()

But io.ReadCloser is not equal []byte (those types).

How can I get stream of Body?

Most helpful comment

Body of net/http package is io.ReaderCloser as you say. Fasthttp implementation returns an array of bytes. It's simply to use with json:

json.Unmarshal(ctx.PostBody(), &yourStructure)

All 2 comments

Body of net/http package is io.ReaderCloser as you say. Fasthttp implementation returns an array of bytes. It's simply to use with json:

json.Unmarshal(ctx.PostBody(), &yourStructure)

If you prefer to use the routing framework instead, forked from fasthttp-routing with JSON support.

https://github.com/jackwhelpton/fasthttp-routing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LeMoussel picture LeMoussel  路  3Comments

bullardla picture bullardla  路  5Comments

mayocream picture mayocream  路  3Comments

ohenepee picture ohenepee  路  4Comments

facundomedica picture facundomedica  路  4Comments