/simple-blog-api

Simple blog api with session auth for teaching frontend

Primary LanguageTypeScript

Blog backend

This is a demo backend application that provides simple CRUD API to use during teaching frontend principles

How to use

  1. Clone the repository
  2. cd to cloned repository
  3. Run yarn to install dependencies
  4. Run yarn build to build the application
  5. Run yarn start to start the server
  6. API should be available under localhost:3001
  7. Remember to adjust proxy configuration of your frontend dev server tool to map to this backend

Routes

All routes accept json payload only, remember to set correct Content-Type header.

Auth

Routes HTTP Request JSON Payload Response Description
/api/auth/signup POST
{
name: string;
email: string;
password: string;
}
Route used to register a new user
/api/auth/login POST
{
email: string;
password: string;
}
Logins the user initializing session
/api/auth/logout POST --- Logs out current user
/api/auth/me GET ---
{
id: string;
email: string;
password: string;
}
Returns current user or 403 if not logged in

Posts

To use this routes (other than GET ones) you need to be logged in.

Routes HTTP Request JSON Payload Response Description
/api/posts GET --- Array of posts Returns all posts
/api/posts/:id GET ---
{
id: number;
createdAt: string;
updatedAt: string;
title: string;
content: string;
published: boolean;
authorId: number;
author: {
id: number;
name: string;
email: string;
}
}
Returns a post of id passed in url
/api/posts/ POST
{
title: string;
content: string;
published?: boolean;
}
Adds new post
/api/posts/:id PUT
{
title?: string;
content?: string;
published?: boolean;
}
Modifies the post of id passed in url
/api/posts/:id DELETE Deletes the post of id passed in url