Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using redirects to make pretty API URLs
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 ```bash [[redirects]] from = "/api/pokemon/:slug" to = "/.netlify/functions/pokemon" status = 200 ``` Now redeploy and we can use our new URL
- Loading branch information