Skip to content

Instantly share code, notes, and snippets.

View michaelrambeau's full-sized avatar

Michael Rambeau michaelrambeau

View GitHub Profile
@michaelrambeau
michaelrambeau / for-await-loop.js
Last active July 6, 2018 14:48
Async iteration with `for await` loop, an example for https://weekly.bestofjs.org/issues/5
/*
Script to run in the latest version of node.js (tested in v10.5.0)
to check the behavior of asynchronous iterators.
*/
// Return a Promise that resolves after 0.5 seconds, to simulate an API request
async function fetchUser(i) {
return new Promise(resolve => {
setTimeout(resolve, 500, `User #${i}`)
})
@JedWatson
JedWatson / KeystoneApiExample.md
Last active July 26, 2021 11:29
Example of how to scaffold API endpoints for Posts in a Keystone project (based on the yo keystone example).

This is an example of how to scaffold API endpoints to list / get / create / update / delete Posts in a Keystone website.

It's a modification of the default project created with the yo keystone generator (see https://github.com/JedWatson/generator-keystone)

Gists don't let you specify full paths, so in the project structure the files would be:

routes-index.js        -->    /routes/index.js         // modified to add the api endpoints
routes-api-posts.js    -->    /routes/api/posts.js     // new file containing the Post API route controllers