SchoolOfCode / bc17-w5d1-catch-up-express-api-with-file-storage-team-egg

bootcamp-17-bc17-w5d1-catch-up-express-api-with-file-storage-hackathon_build-a-backend created by GitHub Classroom
0 stars 1 forks source link

Hackathon - Build a Back End

You'll need to write some code to get this application running. Your server will function as an API like we've been building and also serve an HTML page.

You should see a website at http://localhost:3000 when the server is running. A very basic front-end (HTML/CSS/JS) is currently served. Don't change the front end yet. You'll start by building a back end that fits its needs.

Populate

First, using the table below as a guide, get your CRUD routes up and running in your router so that your server listens for requests and serves test/example responses for now.

Remember that you can test your routes with Postman or Thunder Client to ensure they're working.

Requirements table

Method Path Additional Info Result Response
GET /api/recipes all recipes { success: Boolean, payload: recipe array }
GET /api/recipes/:id recipes with a particular id if it exists { success: Boolean, payload: recipe }
POST /api/recipes { body } create a new recipe { success: Boolean, payload: recipe }
PATCH /api/recipes/:id { body } updated recipe { success: Boolean, payload: recipe }
DELETE /api/recipes/:id recipe deleted { success: Boolean, payload: recipe }

Create your CRUD functionality

There is a recipes.js file in the root of your project. It should contain all of the logic that interacts with the recipe collection. Complete the methods in there, so they behave as expected. These functions should be exported so you can use them in other files later.

The recipe data can be found in recipes.json. The helper functions above should create, read, update and delete (CRUD) recipes from the JSON file.

Hook up helper functions and API endpoints

Import your helper functions into your "app.js" file. Now the focus is to use the helper functions in the route handlers you set up earlier. Each endpoint should perform the correct action and serve the response data. The table above outlines the information you need to do this, including the methods, RESTful path, if there should be a body with the request, expected result, and structure of the response.

Important things to keep in mind

Bonus challenges - THESE ARE OPTIONAL!

Try the challenges below when you're confident that all the routes above work and your API is RESTful.

Prioritize helping your peers in other groups with the requirements above if you get to this point. Remember that articulating to others will strengthen your own understanding!

Join up to the front end

As mentioned above, our server also serves an HTML page as a basic front end, visible when you navigate to http://localhost:3000 in your browser rather than /Thunder Client. You can see this front-end code in the public folder.

The fetch requests are already written in the main.js file, so see if you can get the functionality on the front end interacting with your API.

Optimise the code

Given everything you've learned, try and find ways to refactor and optimise the code. Hint: there's definitely some better ways to go than how we're currently interacting with and manipulating the DOM. Try and remember some of the best practices we explored and see if there's a chance to apply them.

Add middleware

Add middleware to your app. Ideas include:

Add delete functionality to the front-end

Make it so you can delete an individual recipe from the front-end. Plan out exactly the best way to do that - you've already created the back-end functionality.

Keep improving!

If you have time remaining, brainstorm new features you can add to your app on your server or the front end. This could include styling, additional functionality, error handling, additional query options, and more.