Skip to content

PerryGamerPT/APITemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

APITemplate

A simple API in Node.js + Express with dynamic route loading and automatic documentation via Swagger.

Features

  • Express server with JSON support
  • Automatic route loading from the api/routes folder
  • Swagger documentation available in /docs
  • Ready-to-use endpoint example

Project Structure

  • api/index.ts: application entry point
  • api/config/routerLoader.ts: dynamic route loading and Swagger
  • api/routes/: organization of routes by module

Requirements

  • Node.js 18+
  • pnpm / npm

Installation

pnpm install

npm install

Environment Variables

Create a .env file based on .env.example:

API_PORT=3000

Execution

pnpm api
npm run api

The API will be available at:

Example of a request

curl -X POST http://localhost:3000/api/example/add \
  -H "Content-Type: application/json" \
  -d '{"name":"Maria","adresse":"Lisboa"}'

Security and Best Practices

  • The server disables the x-powered-by header
  • The body is limited to 100kb
  • Basic input validation has been added to the example endpoint
  • Avoid exposing secrets in the repository and keep the .env file out of version control

Suggestions for Improvement

  • Add authentication and authorization
  • Insert more robust validation with zod or joi
  • Add automated tests
  • Better separate business logic from handlers

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages