We want our API to be accessible on the /api/pokemon
route, so in netlify.toml
we can add a rewrite, which is different than a redirect.
A redirect will change the url in the browser, while a rewrite will not. So the user will still see /api/pokemon/:slug
instead of seeing the URL change to /.netlify/functions/pokemon
. We specifically need to use the 200
status code to get a rewrite.
We can put the rewrite in the netlify.toml
under the redirects
key. Netlify allows us to specify a from
url, a to
url, the status code, and more if we wanted
[[redirects]]
from = "/api/pokemon/:slug"
to = "/.netlify/functions/pokemon"
status = 200
Now redeploy and we can use our new URL