I have a signup action that takes an email as a form input using FormData & adds a value to database.
I want to simulate rate limit using just fetch api. How can I do that?
I don't want to use playwright or simulate 100s of requests in browser by having another button.
I just want to use fetch. Is it technically possible?
I tried with the following code:
async function main() {
const formData = new FormData()
formData.append('email', '[email protected]')
const res = await fetch('http://localhost:3000/signup', {
method: 'POST',
body: formData,
})
const data = await res.json()
console.log({ data })
}
main()
And typed tsx ./rate-limit/signup.ts in the terminal.
But it only gave me the html back.
Curious if its possible at all like /api routes?
You have to provide the
Next-Actionheader:I didn't find out how to get this action id automatically but manually you can obtain it by inspecting the request headers in the network tab of the browser dev tools.
Edit: You can find
Next-Actionnumber by using a library likecheerio. I used a faster one. Here's a little script: