abdelhak002 / Alos_act1

The first activity of the ALOS Project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ALOS Activity 1

cache-control

req.headers({
  "cache-control": "no-cache",
})
  • The no-cache response directive indicates that the response can be stored in caches, but the response must be validated with the origin server before each reuse, even when the cache is disconnected from the origin server.

installation

clone the repository

git clone https://github.com/abdelhak002/Alos_act1.git

enter the folder

cd Alos_act1

install the packages

npm install

Start server

start the server in development mode by running the cmmnade

npm run watch

Informations

Endpoints

GET all records http://localhost:3000/recipes

GET first ten records http://localhost:3000/recipes?_limit=10

GET records that starts with "M" http://localhost:3000/recipes?title_like=M

GET single record http://localhost:3000/recipes/{id}

The Used Method

we used pure JavaScript to fetch the data.

in Listing2.js file you will find three methods getAll(), getTen(), filterByM() each method has the following code:

async function funName(){
  const api = "http://localhost:3000/recipes"; // store the endpoint in constant variable.

  const response = await fetch(api); // the fetch() function get the data of that endpoint and store it in a constant variable called response.

  const data = await response.json(); // we take that response and convert it to json object by using the json() function and store it in a constant variable called data.

  data.forEach((item) => {console.log(item.element)}) // we take the data object and loop through its elements and print out the desiered element.
}

Note: We used an index.html file to display the data.

Note: The style we used is from the CSS Framework Tailwindcss CDN, It needs iternet connection to function.

About

The first activity of the ALOS Project.


Languages

Language:JavaScript 61.4%Language:HTML 36.7%Language:Shell 1.9%