- Setup an API with a project structure like:
/client
--/server
----/routes
------index.js
------chirps.js
----server.js
----chirpsstore.js (file provided in this lab)
- In
routes/chirps.js
, createGET
,POST
,PUT
,DELETE
methods on a router that is created inchirps.js
.- Import
chirpsstore
, and use it to read and write chirps to the json file.- The json file will be created the first time you run successfully!
- Remember to export your router with
module.exports
.
- Import
- In
routes/index.js
, import thechirps
router and add it to a new router.- Use
app.use
with the/chirps
route to add to the rootapi
router. - Export the router.
- Use
- In
server.js
, import the routes folder (./routes
).- Add the
api
router to the express app with the path/api
.
- Add the
- Test all of your methods using Postman (https://www.getpostman.com/)
- Create an
index.html
,styles.css
, andapp.js
file in theclient
folder.- Code an app that uses jQuery to call your API and displays chirps.
- Create a form that lets you create new chirps
- Do not use a form submit (you only need the inputs and not necessarily a form!)
- Use a button
click
event to call the API.
- Add an
x
next to each chirp that will delete the chirp when clicked. - When a chirp is clicked, popup a modal that lets you edit the chirp.
- Create a form that lets you create new chirps
- Code an app that uses jQuery to call your API and displays chirps.
- Remember to use
express.static
middleware! - HINT: jQuery functions for calling APIs:
$.ajax
,$.get
,$.post