Code Monkey home page Code Monkey logo

node_krowdy's Introduction

Node Class

This is a course to introduce to basic and intermedia knowledge about backend with node js

First Class

¿Que es API?

Un API no es una bd ni un server. Un API es el codigo que gobierna los access points del server.

Nos enfocaremos en API basada para web.

  • API para recibir información detallada
  • Un api para intercambiar data entre aplicaciones.

Gracias a las API podemos acceder a la misama data para diferentes aplicaciones.

  • Diferencia con un backend-bd a una API

Tarea


Simple API

Para crear un packadge json

npm init --yes

Luego una libreria para crear la API

npm i restify

Primero crear el archivo index

luego llamamos la libreria

const restify = require('restify')

Para inicializar restify para crear un server

const server = restify.createServer();

Usar los pluggins de restify -- para que acepte ciertos tipos de cabecera

Server.use(restify.pluginsacceptParser(server.acceptable))

Necesito funcionalidad para convertir las query

server.use(restify.plugin.queryParse())

Para poder entender los json que conteste el server

server.use(restify.plugins.bodyParse())

Luego arrancamos el servidor

server.listen(6000, () => { console.log('server en el puerto 6000'); });

Luego simulamos la bd --- podemos simularla con un arreglo o un objeto (realmente no importa para este ejemplo porque lo almacenamos en memoria y puede ser una constante variable objeto)

const users={ 1:{ name: 'Crispy', lastName: 'Huertos' } };

En las rutas cuando obtengamos la ruta /user .. ejemplo localhost/users , que le responda (funcion) datos almacenado con un error y una respuesta... y un callback que generalmente es llamado next.

Luego decimos 'res' o respuesta , le decimos establece la cabecera. En la cabecera decimos que tipo de dato estamos enviando y que tipo de app es. Luego enviamos el status... en este caso 200.

Finalmente enviamos el dato de vuelta, con stringfy convertimos un json a un string.

Luego crearemos otra ruta. Para retornar por id.

Second class

Comming soon..

node_krowdy's People

Contributors

mokuzaru 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.