background preloader

Creating RESTful APIs With NodeJS and MongoDB Tutorial (Part II) - Adrian Mejia’s Blog

Creating RESTful APIs With NodeJS and MongoDB Tutorial (Part II) - Adrian Mejia’s Blog
Welcome to this RESTful API using Node.js (Express.js) and MongoDB (mongoose) tutorial. You can follow alone to make a stand alone API endpoint, or you could also check out our AngularJS or BackboneJS tutorials to build a javascript-client that connects with the endpoint we are going to built. What RESTful API really means? REST stands for Representational State Transfer. HTTP RESTful API’s are compose of: HTTP methods, e.g. Here’s is a summary what we want to implement: NOTES: * Format will be JSON. * Bulk updates and bulk destroys are not safe, so we will not be implementing those. * POST, GET, PUT, DELETE == CREATE, READ, UPDATE, DELETE == CRUD. Setup The two main components of the MEAN stack are… NodeJS and MongoDB. Note: If already have installed NodeJS, MongoDB (Mongoose), ExpressJS and knows about them separately then you can jump to wiring the stack, which is where the hands on start. NodeJS For short NodeJS is Javascript running outside the browser, in this case in the server. MongoDB

Handle GET and POST Request in Express 4 | Code for geek As per the documentation GET request are meant to fetch data from specified resource and POST are meant to submit data to a specified resource. Express allows you to handle GET and POST request using the instance of express. Due to the depreciation of connect middle-ware handling POST request however seems confusing to many people. GET request: Handling GET request in Express seems so easy. var express = require("express");var app = express(); app.get('handle',function(request,response){//code to perform particular action. GET request can be cached and remains in browser history. POST Request: Express version 4 and above requires extra middle-ware layer to handle POST request. You can install bodyParser by two way. sudo npm install --save body-parser You have to import this package in your project and tell Express to use this as middle-ware. Once configured you can use app.post express router to handle POST request. In this way you can handle the GET and POST request in Express 4. server.js

nodejitsu/node-http-proxy node.js - how to put nodejs and apache in the same port 80 Node.JS et Express Je me rends compte que dans ce blog je vous parle de Node.JS et d’Express, sans vous avoir jamais présenté ces technologies. Allez, revenons vite fait aux bases Installation Pour l’installation, je vous renvoie au site officiel, ou à un article en français par Atinux, mais globalement l’installation se résume à ces 3 lignes: Présentation de Node.JS Node.JS est un projet open-source se basant sur le moteur « V8″ de Chrome (il existe un fork « SpiderNode » par Mozilla, basé sur leur moteur SpiderMonkey). Il s’agit donc finalement d’un simple interpréteur Javascript, exécutable, et enrichissant le langage avec sa propre API (accès au système de fichier, à la couche réseau, etc.). Tout ça tombe bien, les gens du Web a priori savent déjà un peu utiliser Javascript Il y a un exemple de serveur http sur la page d’accueil, donc pour changer je vous mets un exemple de requête vers une base de données utilisant node-mysql illustrant une série d’appels asynchrones: Les modules Les dépôts de modules: NPM

Related: