Skip to content

Full CRUD REST API using Node.js with no framework or dependencies

Notifications You must be signed in to change notification settings

JonasJs/vanilla-node-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vanilla Node REST API

Full CRUD REST API using Node.js with no framework or dependencies

This project was developed for learning and experimentation purposes. In production projects, you would typically use frameworks like Express. However, this project was implemented entirely in vanilla Node.js, without the use of any frameworks or external dependencies.

Features

The project implements a full REST API with the following features:

  • Create a task
  • List all tasks
  • Update a task by id
  • Delete a task by id
  • Mark a task as complete by id
  • Bulk import tasks via a CSV file

Data Guard

For this project, a custom JSON validator called data-guard was created, inspired by libraries such as Zod and Yup. data-guard validates the structure and data of tasks, ensuring they are correct before being processed by the API.

Usage Examples

  • Schema and Data
    const schema = {
      name: { type: 'string', required: true },
      age: { type: 'number' },
      email: 'string',
    };
    
    const data = {
      name: 'John Doe',
      age: 30,
      address: '123 Main St',
    };

Expected Result:

An error should be returned because the address key is not in the schema.

If address were removed, it should return { name: 'John Doe', age: 30 }.

Routes

# Routes
POST     /tasks
GET      /tasks
PUT      /tasks/:id
DELETE   /tasks/:id
PATCH    /tasks/:id/complete

Usage

Installation

# Install dependencies
npm install

Running the Project

# Run in development mode
npm run dev

# Run in production
npm start

Contribution

Contributions are welcome! Feel free to open issues and pull requests.

License

This project is licensed under the MIT License.

About

Full CRUD REST API using Node.js with no framework or dependencies

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published