constfetch=require('node-fetch');constAPI_URL='http://localhost:3000';constENDPOINT='products';// --------- GETfetch(`${API_URL}/${ENDPOINT}`,{"method": "GET"}).then(response=>response.json()).then(json=>console.log(json)).catch(err=>console.error(err));// --------- POSTfetch(`${API_URL}/${ENDPOINT}`,{method: 'POST',body: JSON.stringify({"name": "New item adicionado com NODEJS","description": "npm init e tals","price": 19.90,"category_id": 1}),headers: {'Content-Type': 'application/json'},}).then(res=>res.json()).then(json=>console.log(json));// --------- PUTconstproduct_id_to_put=8;fetch(`${API_URL}/${ENDPOINT}/${product_id_to_put}`,{method: 'PUT',body: JSON.stringify({"name": "PRODUTO 8 ATUALIZADO","description": "description atualized","price": 59.90,"category_id": 2}),headers: {'Content-Type': 'application/json'},}).then(response=>response.json()).then(json=>console.log(json)).catch(err=>console.error(err));// --------- PATCHconstproduct_id_to_patch=12;fetch(`${API_URL}/${ENDPOINT}/${product_id_to_patch}`,{method: 'PATCH',body: JSON.stringify({"name": "Item 12 nome atualizado","price": 39.90,}),headers: {'Content-Type': 'application/json'},}).then(response=>response.json()).then(json=>console.log(json)).catch(err=>console.error(err));// --------- DELETEconstproduct_id_to_delete=3;fetch(`${API_URL}/${ENDPOINT}/${product_id_to_delete}`,{method: 'DELETE'}).then(response=>response.json()).then(json=>console.log(json)).catch(err=>console.error(err));// --------- FILTER BY NAMEconstfilterName='Sushi';fetch(`${API_URL}/${ENDPOINT}?name=${filterName}`,{"method": "GET"}).then(response=>response.json()).then(json=>console.log(json)).catch(err=>console.error(err));// ---------- ORDER BYconstORDER='DESC';constSORT='preco';fetch(`${API_URL}/${ENDPOINT}/?_sort=${SORT}&_order=${ORDER}`,{"method": "GET"}).then(response=>response.json()).then(json=>console.log(json)).catch(err=>console.error(err));// ----------- PAGINATIONletpage=3;letlimit=4;fetch(`${API_URL}/${ENDPOINT}/?_page=${page}&_limit=${limit}`,{"method": "GET"}).then(response=>response.json()).then(json=>console.log(json)).catch(err=>console.error(err));
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].