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
bodyof aPOSTrequest, that you useJSON.stringifyto properly encode them. - A
GETrequest using fetch cannot havebodycontent associated with it. Thebodycontent in JSON is best used withPOSTorPATCHrequests. My dilemma was that I had copied one fetch request, which was aPOSTrequest and started using it as aGETwithout removing the declaration of the body content. - When sending
bodycontent in aPOST, ensure that thecontent-typeis set toapplication/json. Otherwise, it will treat the body content as plaintext, which would explain why myreq.bodywas coming back as undefined.
Just a couple of REST reminders as you go out and make your APIs and request routes.