Why can’t your GET request be called multiple times? If it changes data, then 
you 
should make it a POST/PUT/PATCH request; 

Then with the POST/PUT/PATCH request, you could have an authenticity token 
that you verify is correct before processing any requests. (Which is sort of 
what 
Aria is suggesting).

If the route doesn’t change or create data, and simply reads it, then you could 
set 
up caching for your API Requests.


However, given your message on 13th November at 7:38 pm UTC, I’d be inclined
to say that your misusing GET requests if your “creating” things.

— Micheil

On 13 Nov 2014, at 5:59 pm, Alex Spencer <[email protected]> wrote:

> Hi.
> 
> Imagine a simple route like this:
> 
> app.get('/test',
> apiCall1(),
> apiCall2(),
> apiCall3(),
> apiCall4(),
> apiCall5(),
> renderPage()
> 
> How would you prevent this code from being executed by the same client while 
> said client is spamming GET requests (either by refresh page or clicking 
> buttons, etc.) to the same route ?
> 
> I'm using express (+session, static, bodyparser) and have failed to figure 
> this out on my own.
> 
> For example when I first visit /test in the browser, it works fine. But if I 
> then quickly refresh the page twice in a row, I get to the route twice for 
> the same session, which in turn doubles the amount of API calls from 5 to 10.
> 
> I want it to only occur once, and render the page. I've tried session 
> variables like "isRequesting true/false" and such, but nothing works, because 
> the response object changes upon a new request, meaning renderPage cant use 
> res.send on the "latest" response object.
> 
> 
> Cheers.
> 
> -- 
> Job board: http://jobs.nodejs.org/
> New group rules: 
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules: 
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> --- 
> You received this message because you are subscribed to the Google Groups 
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/nodejs/cf81af35-399e-4842-8d9d-d8095d54f3bc%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/797A3DE8-56EA-4535-86A6-1EE4D0D34080%40brandedcode.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to