I've created a website based on my API - so that my FrontEnd is decoupled from the backend using a simple REST API (frontend is pure javascript/html).
I would like to protect the API from usage by anyone else - so that the calls can come from the website alone (or maybe allow other specific websites to use it).
For now, if anyone would use curl
he will be able to scrape the API very easily.
How can I protect the API assuming the FrontEnd is JS/Html only, so that legitimate calls from my own pages work but curl
and such from third parties do not?
This question may not be a good fit for SO, as there can be multiple equally-valid answers.
But one way to do this would be to use SSL, user authentication, and tokens. Here's a rundown:
The user authentication part of that is important, because otherwise, while you'd be pretty safe from remote hacking (because of the SSL), a hacker who uses a browser to go to your site so he/she can get the token can then use
curl
or similar to his/her heart's content with that token. So if someone is mining your site, you at least want to have some clue who they might be (your user authentication) so you can get them to stop.