Closed nstansbury closed 5 years ago
are you asking me to update the documentation? What type of request body are you trying to access?
The two I have tried so far are text/plain
and application/jwt
- the data is just a base64 encoded string.
Apologies, I should clarify I'm following the docs here: https://github.com/lwsjs/local-web-server/wiki/How-to-prototype-a-REST-API-using-Mock-Responses and just mocking some PUT
requests
i will update the docs tonight with some examples, thanks.
If you think you've found a bug, please post a reproduction case. Otherwise, try running ws
with the --verbose
flag to inspect all traffic..
Some examples would be great thank you.
I'm pretty certain the error is in my code. I'm unclear as to whether we need to require the full require('koa');
app as per their docs here: https://github.com/koajs/bodyparser or if there's some heavy lifting done by lws-body-parser
etc
The easiest option in the end was to revert to the application/json
content-type and serialise & send the string inside an array - JSON.stringify([string])
. In the handler I just had to call ctx.request.body[0];
Attempting to access a non-JSON request body
The docs here: https://github.com/lwsjs/local-web-server/wiki/How-to-access-the-body-of-an-incoming-request
require('lws-body-parser')
but don't tell you how to use itThe docs here: https://github.com/lwsjs/local-web-server/wiki/Using-middleware#built-in-middleware-stack
Suggest the
lws-body-parser
is in the default stack.ws middleware-list
confirms it is.Unless the application type is
application/json
thectx.request.body
/ctx.request.rawBody
etc is either undefined or{}