Just a quick post today, but this one unfortunately sidetracked me for a bit. Just remember a couple of things:
- Always ensure that when providing objects as
body
of aPOST
request, that you useJSON.stringify
to properly encode them. - A
GET
request using fetch cannot havebody
content associated with it. Thebody
content in JSON is best used withPOST
orPATCH
requests. My dilemma was that I had copied one fetch request, which was aPOST
request and started using it as aGET
without removing the declaration of the body content. - When sending
body
content in aPOST
, ensure that thecontent-type
is set toapplication/json
. Otherwise, it will treat the body content as plaintext, which would explain why myreq.body
was coming back as undefined.
Just a couple of REST reminders as you go out and make your APIs and request routes.