{"info":{"_postman_id":"7a68e3fb-78f8-40be-bc7b-d804906b766f","name":"API NodePop","description":"<html><head></head><body><h1 id=\"introduccion\">Introducción</h1>\n<ul>\n<li>Proyecto backend del API de la app Nodepop, creada como practica parte del curso de Desarrollo Backend con Node.js del Bootcamp Web 7 de Keepcoding.</li>\n<li>El servicio mantiene anuncios de compra o venta de artículos y permite consultar, y buscar filtros por varios criterios.</li>\n</ul>\n<h1 id=\"overview\">Overview</h1>\n<p>Tecnologías: Este proyecto usa EXPRESS, MongoDB, mongoose y Node.js. Se puede conocer las dependencias en package.json.</p>\n<h2 id=\"mongodb\">MongoDB</h2>\n<p>Para este proyecto es necesario tener instalado MongoDB. Primero vamos a arrancar un servidor MongoDB local escribiendo la siguiente lìnea en un terminal:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-js\">    &gt; ./bin/mongod --dbpath ./data/db --directoryperdb\n</code></pre>\n<h2 id=\"instalar-dependencias\">Instalar dependencias</h2>\n<p>Un paso importante antes de arrancar el servidor es instalar todas las dependencias del proyecto. Para hacerlo, en un terminal ejecutamos lo siguiente:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-js\">    &gt; npm install\n</code></pre>\n<h2 id=\"inicializar-base-de-datos\">Inicializar Base de Datos</h2>\n<p>En este proceso se crearà y cargará una colección de documentos de la base de datos necesaria para el funcionamiento de la aplicación 'nodepop', para esto ejecutamos el script installDB dentro del package.json:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-js\">    &gt; npm run installDB\n</code></pre>\n<h2 id=\"iniciar-server-app\">Iniciar server App</h2>\n<p>Hay varias formas de iniciar o arrancar nodepop:</p>\n<ul>\n<li>En modo DEBUG para el desarrollo, ejecutamos en un terminal:</li>\n</ul>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-js\">    &gt; npm run dev\n</code></pre>\n<ul>\n<li>En modo Produción, ejecutamos:</li>\n</ul>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-js\">    &gt; npm run prod\n</code></pre>\n<blockquote>\n<p>Puedes conocer mas revisando el apartado scripts en el archivo de configuración package.json</p>\n</blockquote>\n<h1 id=\"authentication\">Authentication</h1>\n<p>Aun no cuenta con autenticación.</p>\n<h1 id=\"error-codes\">Error Codes</h1>\n<h1 id=\"rate-limit\">Rate limit</h1>\n<h1 id=\"api-methods\">API Methods</h1>\n<p>El Api de nodepop esta basada en principios REST y usa los métodos HTTP(GET y POST) para acceder a los recursos.\nEl formato de transferencia soportado por el API para enviar y recibir respuestas es en JSON.</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-json\">    {\n     \"success\": true,\n     \"result\": []\n    }\n</code></pre>\n<p>Además el json a recibir, nos devolverá una propiedad success, la cual estará en true cuando la respuesta se ha resuelto satisfactoriamente, y false cuando hubo algún error en la petición.</p>\n<h2 id=\"endpoint-anuncios\">Endpoint /anuncios</h2>\n<p>El endpoint /anuncios en nuestra API nos permitirá consultar, paginar, y filtrar datos de todos los anuncios registrados en la base de datos MongoDB de nuestra aplicación Nodepop.</p>\n<h2 id=\"recursos\">Recursos</h2>\n<p>Los recursos son todos los métodos, y filtros aplicados o disponibles para un endpoint en este caso el de /anuncios:</p>\n<ul>\n<li>/anuncios/ - obtener todos los anuncios de nodepop.</li>\n<li>/anuncios/:id - obtener un anuncio específico.</li>\n</ul>\n</body></html>","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[{"content":"Introducción","slug":"introduccion"},{"content":"Overview","slug":"overview"},{"content":"Authentication","slug":"authentication"},{"content":"Error Codes","slug":"error-codes"},{"content":"Rate limit","slug":"rate-limit"},{"content":"API Methods","slug":"api-methods"}],"owner":"3162339","collectionId":"7a68e3fb-78f8-40be-bc7b-d804906b766f","publishedId":"SVn3sFCr","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"EF5B25"},"publishDate":"2019-09-27T07:34:32.000Z"},"item":[{"name":"Lista de Anuncios","id":"58802af3-29c8-4419-b15e-42e332a95fda","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"Content-Type","name":"Content-Type","value":"application/x-www-form-urlencoded","type":"text"}],"body":{"mode":"urlencoded","urlencoded":[{"key":"nombre","value":"Monitor","type":"text"},{"key":"venta","value":"false","type":"text"},{"key":"precio","value":"200","type":"text"},{"key":"foto","value":"","type":"text"},{"key":"tags","value":"work","type":"text"},{"key":"tags","value":"lifestyle","type":"text"}]},"url":"http://localhost:3000/apiv1/anuncios","description":"<p>Recurso del endpoint /anuncios que retorna una lista de todos anuncios.</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios"],"host":["localhost"],"query":[],"variable":[]}},"response":[{"id":"f4e230ed-331d-4f82-b4d1-d11102b82de5","name":"Default","originalRequest":{"method":"POST","header":[],"body":{"mode":"raw","raw":""},"url":"http://localhost:3000/apiv1/anuncios"},"code":200,"_postman_previewlanguage":null,"header":null,"cookie":[],"responseTime":null,"body":""}],"_postman_id":"58802af3-29c8-4419-b15e-42e332a95fda"},{"name":"Seleccionar campos","id":"ca83d5dd-0178-4eac-ae07-afe7fbde7819","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"http://localhost:3000/apiv1/anuncios?start=0&limit=2&fields=nombre precio","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios"],"host":["localhost"],"query":[{"key":"start","value":"0"},{"key":"limit","value":"2"},{"key":"fields","value":"nombre precio"}],"variable":[]}},"response":[],"_postman_id":"ca83d5dd-0178-4eac-ae07-afe7fbde7819"},{"name":"Omitir campo _id","id":"9e1bbfd9-bb9a-463b-b7c3-f50cfa538987","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"http://localhost:3000/apiv1/anuncios?start=0&limit=2&fields=nombre precio -_id","description":"<p>Esta petición nos devuelve los eventos sin mostrar el campo _id.</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios"],"host":["localhost"],"query":[{"key":"start","value":"0"},{"key":"limit","value":"2"},{"key":"fields","value":"nombre precio -_id"}],"variable":[]}},"response":[],"_postman_id":"9e1bbfd9-bb9a-463b-b7c3-f50cfa538987"},{"name":"Ordenar campos","id":"a7e2c6fa-1c83-4478-aec2-0a0c257bad16","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"http://localhost:3000/apiv1/anuncios?start=0&limit=2&sort= precio","description":"<p>Esta petición me devolverá eventos ordenando según el campo que le pase al parámetro <code>sort</code>.</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios"],"host":["localhost"],"query":[{"key":"start","value":"0"},{"key":"limit","value":"2"},{"key":"sort","value":" precio"}],"variable":[]}},"response":[],"_postman_id":"a7e2c6fa-1c83-4478-aec2-0a0c257bad16"},{"name":"Listar por tipo de Anuncio","id":"f7bea860-7aef-498b-b0e8-2803b1ad2fc8","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"http://localhost:3000/apiv1/anuncios?venta=true","description":"<p>Esta petición nos permite filtrar anuncios según el tipo, en venta si el parametros es true y compra si el parámetro es false.</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios"],"host":["localhost"],"query":[{"key":"venta","value":"true"}],"variable":[]}},"response":[],"_postman_id":"f7bea860-7aef-498b-b0e8-2803b1ad2fc8"},{"name":"Filtros por tags","id":"4551feda-0857-4f16-841e-fc3b974ad9a8","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"http://localhost:3000/apiv1/anuncios?tags=mobile motor","description":"<p>En esta petición listamos todos los anuncios cuyo campo tags contengan <code>mobile</code> y <code>motor</code>.</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios"],"host":["localhost"],"query":[{"key":"tags","value":"mobile motor"}],"variable":[]}},"response":[],"_postman_id":"4551feda-0857-4f16-841e-fc3b974ad9a8"},{"name":"Filtro por rango de precio","id":"3c6fe8da-d622-4cbf-accb-1537919f5d99","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"http://localhost:3000/apiv1/anuncios?precio=10-30","description":"<p>La petición del ejemplo 6 nos devuelve los anuncios cuyo rango de precio este entre &gt;= a 10 y &lt;= a 30.</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios"],"host":["localhost"],"query":[{"key":"precio","value":"10-30"}],"variable":[]}},"response":[],"_postman_id":"3c6fe8da-d622-4cbf-accb-1537919f5d99"},{"name":"Error al filtrar por precio","id":"bcca5623-b400-420f-b38d-ac4c7f122fb2","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"http://localhost:3000/apiv1/anuncios?precio=30-10","description":"<p>Hay que tener en cuenta que el valor del rango inicial siempre debe ser menor al rango final, en caso de ser mayor devolvera un error 422.</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios"],"host":["localhost"],"query":[{"key":"precio","value":"30-10"}],"variable":[]}},"response":[],"_postman_id":"bcca5623-b400-420f-b38d-ac4c7f122fb2"},{"name":"Búsqueda por nombre","id":"17956678-93cf-4ba6-a893-b7ea37f288cf","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"http://localhost:3000/apiv1/anuncios?nombre=bici","description":"<p>Esta petición nos permite hacer una búsqueda por el campo nombre.</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios"],"host":["localhost"],"query":[{"key":"nombre","value":"bici"}],"variable":[]}},"response":[],"_postman_id":"17956678-93cf-4ba6-a893-b7ea37f288cf"},{"name":"Consultar un Anuncio","id":"dc9d2542-fdf4-4ee4-8430-afa55dcf72ed","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"http://localhost:3000/apiv1/anuncios/5d84855afcc9025b29f6d3ba","description":"<p>Esta petición nos permite buscar un anuncio por su id.</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios","5d84855afcc9025b29f6d3ba"],"host":["localhost"],"query":[],"variable":[]}},"response":[],"_postman_id":"dc9d2542-fdf4-4ee4-8430-afa55dcf72ed"},{"name":"Listar Tags","id":"25a7497b-dcb1-4f35-b498-fac57eef89d2","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"http://localhost:3000/apiv1/anuncios/tags","description":"<p>Recurso del endpoint /anuncios/tags que retorna una lista con los tags existentes.</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios","tags"],"host":["localhost"],"query":[],"variable":[]}},"response":[],"_postman_id":"25a7497b-dcb1-4f35-b498-fac57eef89d2"},{"name":"Crear un anucio","id":"ed26eff9-87cc-4167-b3be-d4d325360467","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Content-Type","name":"Content-Type","value":"application/x-www-form-urlencoded","type":"text"}],"body":{"mode":"urlencoded","urlencoded":[{"key":"nombre","value":"Monitor","type":"text"},{"key":"venta","value":"false","type":"text"},{"key":"precio","value":"200","type":"text"},{"key":"foto","value":"","type":"text"},{"key":"tags","value":"work","type":"text"},{"key":"tags","value":"lifestyle","type":"text"}]},"url":"http://localhost:3000/apiv1/anuncios","description":"<p>Esta petición permite crear un nuevo anuncio y guardarlo en la base de datos.</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios"],"host":["localhost"],"query":[],"variable":[]}},"response":[],"_postman_id":"ed26eff9-87cc-4167-b3be-d4d325360467"},{"name":"Actualizar un Anuncio","id":"9f72862a-d59d-4c9a-97fe-d04dc6133918","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"PUT","header":[{"key":"Content-Type","name":"Content-Type","value":"application/x-www-form-urlencoded","type":"text"}],"body":{"mode":"urlencoded","urlencoded":[{"key":"nombre","value":"Monitor LG","type":"text"},{"key":"venta","value":"false","type":"text"},{"key":"precio","value":"300","type":"text"},{"key":"foto","value":"","type":"text"},{"key":"tags","value":"work","type":"text"}]},"url":"http://localhost:3000/apiv1/anuncios/5d90a457c4d2501fec3af158","description":"<p>Actualiza un anuncio</p>\n","urlObject":{"protocol":"http","port":"3000","path":["apiv1","anuncios","5d90a457c4d2501fec3af158"],"host":["localhost"],"query":[],"variable":[]}},"response":[],"_postman_id":"9f72862a-d59d-4c9a-97fe-d04dc6133918"}]}