Database to page routing API?


Lets say I have in my database a table for Universities – and for each entry in the database, the primary key would be the name of the University, i.e Duke.

If I created a template for all the university pages i.e university-template, is it possible to have an automatic routing to the specific universities page ( university-template updated with data from the database )?

i.e when someone accesses the university-template is populated with the Duke entry from the database table. If the entry (in above examble, university/{slug}, slug is the entry to be searched) is not stored in the table then send the user to different custom template like uni-not-found-error-template.

Or do I need to create a page for each university ( like this question )

My current idea is to write a custom API that functions like so:
User sends GET request: GET
University Table is queried for slug: Duke
If value error: send user to custom error page
If valid: pull template and fill corresponding Duke data from table
Display to page to User.

, , , Adam Kit 3 years 2020-03-30T12:51:16-05:00 0 Answers 99 views 0

Leave an answer