I created a microservice in Go that unmarshals the data off of a request body and stores it in DynamoDB. The REST URL runs pretty much anywhere but a browser it seems. When I run the fetch in a browser I get a 403 with no response. I can get a 200 response using a Node script, curl command, or even when using a tool like repl.it to test. For some reason though, it never wants to work in a web app, or the dev console (I'm using Chrome). I tried running the request in multiple websites including the web app I'm building to run it in and all of them gave the same 403 no response result.
In API Gateway, Authorization is set to "none", and API Key is set to "not required", so I'm having a lot of difficulty in seeing how I can get a 403 on my endpoint. On the frontend, my fetch request looks like something below. The curl command that worked is below as well. I followed this post before creating this, and although it's similar, this person does actually get a response, while mine gives me no response. It works as a script, but just doesn't work in the browser. How does this work anywhere but inside a browser? If I can just get some info on what's going on, that would be awesome. If I can get some info on how this can be solved, that would be REALLY awesome.
js
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
data: JSON.stringify({
Email: 'example@test.com'
}),
})
.then(res => res.json())
.then(json => console.log(json))
.catch(e => console.error(e))
curl
curl -H 'application/json' -d '{ "Email": "example@test.com" }' $URL
UPDATE: I discovered what I had going wrong. It was a CORS issue. I was not handling the OPTIONS method that was sent as a preflight request prior to my POST request. The OPTIONS method gets sent automatically when in the browser, but does not if you're running the code anywhere else.