Skip to content

Instantly share code, notes, and snippets.

View colinskow's full-sized avatar

Colin Skow colinskow

  • Las Vegas, NV
View GitHub Profile
@colinskow
colinskow / api.js
Last active May 8, 2018 19:45
Passing parameters to an API
app.get('/api/todo/:key', (req, res, next) => {
todos.findOne({ key: req.params.key })
.then(result => {
if (!result) {
return next({ status: 404, message: 'not found' });
}
res.status(200).json(result);
})
.catch(err => {
return next({ status: 500, message: err.message });
@colinskow
colinskow / app.js
Last active January 25, 2018 21:25
Simple JSON API with Express
const express = require('express');
const app = express();
let nextId = 1;
let todos = [];
function addTodo(text) {
const id = nextId;
todos = [...todos, {
id,