-
This is the correction of a workshop created for the WBS Coding School to make web dev students practice their Back-end skills.
Clone this repo mini-yelp
on your computer, then go into the folder with your terminal and execute:
npm install
Create a locally hosted postgres database
Create a .env
file at the root of the project
Put the database credentials into your .env file as such:
PGHOST=<Your database host>
PGUSER=<Your database user>
PGDATABASE=<Your database name>
PGPASSWORD=<Your database password>
PGPORT=5432
If you choose this option, run npm run dev
and try to hit http://localhost:3000/
You should get Welcome to Mini-Yelp!
as a reply.
Deploy the project on Heroku following this documentation
Create a database hosted on Heroku Postgres and link it to your project.
Make sure the DATABASE_URL
env variable is defined and that the DB connection string is passed on to the app.
(Note: You can also use ElephantSQL, but it comes with some limitations for the seeding)
Before you can execute any commands on the API; you need to initialize and seed some fake data into the database.
Fortunately, there's a /seed
route for this!
To test our API, we need a software called Postman or Insomnia, it will allow us to fire some queries on our endpoints.
So launch Postman (or Insomnia) and execute the following requests:
POST /seed/create
then
POST /seed
You should see Database successfully created
for the first command and the seeded data for the second.
If at any point after playing around with the database you need a clean slate; you can run:
DELETE /seed/destroy
This will drop all tables. You can then redo the creation and the seeding accordingly to start fresh.
Now you can query the API 🥳
You could start by checking all the restaurants located in a city:
GET /city/4
or
You could get all the restaurants with their associated data (comments/tags/city) as such:
GET /restaurant
You can control if you want to retrieve all the associated information for the restaurants by passing a JSON object in the body of your request:
{
"comments": false,
"tags": true
}
or
You could search for all restaurants linked to a tag by sending the id of that tag:
GET /tag/7
This is not an exhaustive list.
You're encouraged to check the entities folder and check what you can do with the API! 🤓