Davidihl / react-guest-list-api

Part of the "react-guest-list" UpLeveled.io project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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();

Import to Replit

Create a Replit account at Replit - Sign up, and then click on this button:

Run on Replit

This will import the code from this repo to a new repl on Replit. Once it has been imported, run the application using the green Run button at the top center of the screen.

About

Part of the "react-guest-list" UpLeveled.io project


Languages

Language:TypeScript 95.1%Language:JavaScript 4.9%