Git Product home page Git Product logo

blog_maximo's Introduction

blog_maximo

dia: 16/10/23, hora: 01:10am

agregando express y añadiendo buenas practicas para poder tener un proyecto mantenible en el tiempo :)
me voy a dormir.

dia: 16/10/23, hora: 13:49pm

Creando mi primer servidor con express en el cual se lee "hola carola"
sigan viendo.

dia: 16/10/23, hora: 10:28pm

creando distintas ramas en mi archivo index.js en el backend

dia: 17/10/23, hora 18:37pm

agregue este endpoint:

app.get("/posts/:id/", (req, res) => {
    const { id } = req.params

    const searchedPost = posts.find((post) => post.id == id)

    if (searchedPost === undefined) {
        res.status(404).send('Err 404: Se produjo un error al buscar el post');
    }
    else {
        res.send(searchedPost);
    }
})

y hice posts una variable global

dia 17/10/23, hora 21:33pm

agregue otro endpoint mas para buscar por los tags:

app.get("/posts/tags/:tag", (req, res) => {
    const { tag } = req.params;
    const filteredPostsByTag = posts.filter((post) => post.tags.includes(tag));

    if(filteredPostsByTag === undefined) {
        res.status(404).send('Err 404: Se produjo un error al buscar el post con la etiqueta indicada');
    }
    else {
        res.send(filteredPostsByTag);
    }
});

dia 19/10/23, hora: 12:12pm

cambie el endpoint para buscar por tags a un query parameter

app.get("/posts/tags", (req, res) => {
    const { tag } = req.query;
    const filteredPostsByTag = posts.filter((post) => post.tags.includes(tag));


    if(filteredPostsByTag === undefined) {
        res.status(404).send('Err 404: Se produjo un error al buscar el post con la etiqueta indicada');
    }
    else {
        res.send(filteredPostsByTag);
    }

});

dia 19/10/23, hora: 22:42pm

agregue un sistema rutas con express.Router creando una carpeta llamada routes donde por ahora estan los archivos: "index.js", "postRouter.js", "searchRouter.js"

index.js

const postsRouter = require("./postsRouter")
const searchRouter = require("./searchRouter")

function routerAPI(app) {
    app.use("/posts", postsRouter)
    app.use("/search", searchRouter)
}

module.exports = routerAPI

y use la variable en backend/index.js agregando estas 2 lineas de codigo

const routerApi = require('../routes/index')
routerApi(app)

blog_maximo's People

Contributors

swittv avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.