Open techniJANE opened 4 years ago
Not sure where we should be posting our homework, but this is mine: https://repl.it/@techniJANE/BackToTheFrontEnd#script.js
I tried if () {blah blah blah return} ... and it didn't work, but when I used if () {} else {} everything was working. Can we go over how to use this fancier return version of the if statement again tomorrow in class?
Best practice for structuring JS code:
APIs:
API Codes: Const express = require(‘express’) //go find package called express in the npm, and store it in a constant called express Const app = express() //code explaining how api is supposed to work GET request — gets some information POST request — creating something new PUT or PATCH requests - update some DELETE request — deletes some existing information HEAD request — is everything ok? (RESTful API - representational status transfer - information that’s already stored)
GET request example: app.get(“/message”, (_request,response) => { Response.json({hello: “world”}) })
POST request example: Let counter = 0 App.post(“/counter”, (_request,response) => { counter += 1 response.json({counter: counter}) })
Building an NPI:
app.use(express.json()) - tells the app to be able to read incoming json requests