fetch, no-cors no custom context type

Note: This post was written a while back but sat in draft. I’ve published this now, but I’m not sure it’s relevant to the latest versions etc. so please bear this in mind.

If you’re using the Javascript fetch api with mode set to ‘no-cors’ beware that this limits the set of headers you can use in your request. Specifically if you’re trying to interact with a server using application/json, the ‘no-cors’ will simply not apply that content-type.

See Using Fetch

In no-cors mode only the following are allowed

  • Accept
  • Accept-Language
  • Content-Language
  • Content-Type which can only take the following
    • application/x-www-form-urlencoded
    • multipart/form-data
    • text/plain