→ https://github.com/dupontdenis/Asyn--Projet-MVC-calculette-js.git
Mongoose !
📕Cours
→ https://dupontmongodb.blogspot.com/
🛟Tout en 1
Installation Mongodb ⚒️
mongodb →
🥷Code
https://github.com/dupontdenis/testMongo.git
💸Code avec mongoose
https://github.com/dupontdenis/TESTMONGOOSE.git
Test
https://github.com/dupontdenis/TESTCORSMONGO.git
Let's start
Model : Simulate a DB
🚩 PUT/DELETE how-to
💡 Les navigateurs ne supportent que GET et POST en natif dans les formulaires. Découvrez comment gérer DELETE et PUT.
Méthode CRUD | Support natif HTML | Solution avec Express |
Create (POST) | ✅ Oui | <form method="POST"> |
Read (GET) | ✅ Oui | <form method="GET"> |
Update (PUT) | ❌ Non | method-override + POST |
Delete (DELETE) | ❌ Non | method-override + POST |
Delete/update
- In this repository we keep things explicit and simple by using POST endpoints for update and delete actions (for example
/posts/:id/updateand/posts/:id/delete). Those endpoints accept normal POST form submissions and return normal redirects or rendered pages.
- HTML forms only submit GET or POST.
method-overrideis a middleware used to turn a POST into a PUT/DELETE on the server (usually by reading a hidden_methodfield or a query parameter).
- This project was converted to an API-first, client-rendered demo where the server returns JSON and the frontend (in
public/index.htmlandpublic/js/app.js) usesfetch()to perform CRUD operations.
🍕PizzasAPI
🚀 https://mypizzasapi.onrender.com/
{
"message": "Welcome to Pizza API! 🍕",
"description": "A simple REST API for pizzas - inspired by ghibliapi.dev",
"endpoints": {
"pizzas": "/API/pizzas",
"pizzaById": "/API/pizzas/:id",
"pizzasWithPrices": "/API/pizzasWithPrices",
"ingredientPrices": "/API/ingredientPrices",
🪛"pizzaSearchByIngredient": "/API/pizzas/search?ingredient=🧀",
"pizzaSinglePrice": "/API/pizzasWithPrices/:id/price",
"customPrice": {
"method": "POST",
"path": "/API/pizzasWithPrices/compute",
"body": {
"ingredients": [
"🍅",
"🧀"
]
}
}
}
}Exemples :
🪛Ainsi pour tester l'API avec ingredient=🧀
https://mypizzasapi.onrender.com/API/pizzas/search?ingredient=🧀
🪛Ainsi pour tester l'API avec ingredient=🍅 et ingredient=🍄
https://mypizzasapi.onrender.com/API/pizzas/search?ingredient=🍄&ingredient=🍅
🥷Pour tester : https://dupontdenis.github.io/testMyPizzasAPI/
De vanilla à express
Pour une même application
https://dupontdenis.github.io/filmsGhibli_Vanilla/
Voici différentes implémentations
- Janilla : https://github.com/dupontdenis/filmsGhibli_Vanilla.git
- Express + EJS https://github.com/dupontdenis/filmsGhibli_EJS.git
- Express + pug https://github.com/dupontdenis/filmsGhibli.git
projet
Souriez : projet
Clonez https://github.com/dupontdenis/takepicture.git
Lancez dans un terminal le serveur avec la commande :
node app
Dans votre navigateur allez http://localhost:3000/
Have fun !
Analysez ce code !
Asynchronisme !
Introduction
Cours
Callback, promesses et Async/Await
BD (callback)
TD
🚀Asynchrone dans votre navigateur (es6)
Objectif : comprendre ce code
- async function* getLines() {
- const data = [
- "# Commentaire ignoré",
- "Ligne utile 1",
- "Ligne utile 2",
- "# Autre commentaire",
- "STOP",
- "Ligne après STOP",
- ];
- for (const line of data) {
- await new Promise((resolve) => setTimeout(resolve, 100)); // simule un délai
- yield line;
- }
- }
- async function processUntilStop(lines) {
- for await (const line of lines) {
- if (line === "STOP") break;
- if (line.startsWith("#")) continue;
- console.log(`Traitement : ${line}`);
- }
- console.log("🔚 Fin du traitement.");
- }
- processUntilStop(getLines());
lecture
Analysez ce code :
