/routing

Primary LanguageJavaScriptOtherNOASSERTION

Node API 2 Guided Project Starter Code

Guided project starter code for Node API 2 module.

In this project we will learn how to create a very simple Web API using Node.js and Express, and cover how to use Express Routers to break up the application to make it more maintainable.

Prerequisites

Project Setup

  • fork and clone this repository.
  • CD into the folder where you cloned your fork.
  • type npm i to download dependencies.

Please follow along as the instructor builds the API step by step.

Public Endpoints

  • Hubs Resource: /api/hubs
  • Clients: /api/clients
  • Products: /api/products

Create a Product => /add_product (sad panda) the RESTful way is: POST /api/products Update a Product => /update_product (sad panda) the RESTful way is: PATCH/PUT /api/products/:id

Private Endpoints

  • Clients: /admin/clients
  • Products: /admin/products

Query Strings

The client assembles the URL to include the query string.

localhost:4000/api/hubs?limit=3&page=3

?limit=5 <-- query string

? ---> the beginning a the query string

limit=5 --> key/value pair

& --> separates key/value pairs

page=3 --> key/value pair

On the server we access the query string at req.query;

https://www.amazon.com/s ? k=iphone & i=mobile & rh=n%3A2335753011%2Cp_72%3A2491149011%2Cp_89%3AApple%2Cp_36%3A2491158011 & dc& qid=1586282433 & rnid=2491154011 & ref=sr_nr_p_36_1