Skip to content

upleveled/express-guest-list-api-memory-data-store

Repository files navigation

Express REST Guest List API

A simple, naïve, in-memory RESTful guest list API in Express.

Installation

git clone https://github.com/upleveled/express-guest-list-api-memory-data-store.git
cd express-guest-list-api-memory-data-store
pnpm install
pnpm start

Usage

Base URL

const baseUrl = 'http://localhost:4000';

Getting all guests (aka GET /guests)

const response = await fetch(`${baseUrl}/guests`);
const allGuests = await response.json();

Getting a single guest (aka GET /guests/:id)

const response = await fetch(`${baseUrl}/guests/:id`);
const guest = await response.json();

Creating a new guest (aka POST /guests)

const response = await fetch(`${baseUrl}/guests`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ firstName: 'Karl', lastName: 'Horky' }),
});
const createdGuest = await response.json();

Updating a guest (aka PUT /guests/:id)

const response = await fetch(`${baseUrl}/guests/1`, {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ attending: true }),
});
const updatedGuest = await response.json();

Deleting a guest (aka DELETE /guests/:id)

const response = await fetch(`${baseUrl}/guests/1`, { method: 'DELETE' });
const deletedGuest = await response.json();

Deploy on CodeSandbox

  1. Log in or register on CodeSandbox - Sign in
  2. Return to the express-guest-list-api-memory-data-store GitHub repository and add box between github and .com in the URL (githubbox.com instead of github.com) - this creates a synced template on CodeSandbox
  3. Click on "Fork" at the top right of the page - this creates a devbox in your account from the synced template
  4. Beside "Fork", click "Share", select "Public" from the "Visibility" dropdown and click "Move Devbox" - this allows everybody read access to your devbox

The API can be accessed at the URL in the preview pane on the right (URL ends with csb.app).

Related

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published