/node-ts-restful-api-starter

🔰 A RESTful-API starter, built with TypeScript & Prisma.

Primary LanguageTypeScriptMIT LicenseMIT

Node Express RESTful API Starter (TS)

Introduction

Getting Started

1. Download starter and install dependencies

Clone this repository:

git clone git@github.com:BCIT-DDC/node-ts-restful-api-starter.git

Install npm dependencies:

cd node-ts-restful-api-starter
npm install

2. Start the REST API server

npm run dev

The server is now running on http://localhost:3000. You can now the API requests, e.g. http://localhost:3000/api/users.

Using the REST API

You can access the REST API of the server using the following endpoints:

GET

  • /api/post/:id: Fetch a single post by its id
  • /api/user/:id/drafts: Fetch user's drafts by their id
  • /api/users: Fetch all users

POST

  • /api/post: Create a new post
    • Body:
      • title: String (required): The title of the post
      • content: String (optional): The content of the post
      • authorEmail: String (required): The email of the user that creates the post
  • /api/signup: Create a new user
    • Body:
      • email: String (required): The email address of the user
      • name: String (optional): The name of the user

PUT

  • /api/publish/:id: Toggle the publish value of a post by its id
  • api/post/:id/views: Increases the viewCount of a Post by one id

DELETE

  • /api/post/:id: Delete a post by its id

Project Structure

.
├──  assets
│   └──  icons
│   └──  images
├──  docs
│   └──  contributing
│       └──  types-of-contributions.md
├──  scripts
│   └──  copy-files.script.ts
├──  src
│   ├──  api
│   │   ├──  controllers
│   │   │   ├──  post.controller.ts
│   │   │   └──  user.controller.ts
│   │   ├──  errors
│   │   │   ├──  application.exception.ts
│   │   │   ├──  database.exception.ts
│   │   │   ├──  http.exception.ts
│   │   │   └──  validation.exception.ts
│   │   ├──  helpers
│   │   │   └──  example.helper.ts
│   │   ├──  interfaces
│   │   │   ├──  postData.interface.ts
│   │   │   └──  route.interface.ts
│   │   ├──  middleware
│   │   │   ├──  error.middleware.ts
│   │   │   └──  express.middleware.ts
│   │   ├──  models
│   │   │   └──  example.model.ts
│   │   ├──  routes
│   │   │   ├──  api.route.ts
│   │   │   └──  home.route.ts
│   │   ├──  services
│   │   │   ├──  post.service.ts
│   │   │   └──  user.service.ts
│   │   ├──  utils
│   │   │   ├──  iohandler.util.ts
│   │   │   ├──  logger.util.ts
│   │   │   └──  secrets.util.ts
│   │   └──  validators
│   │       ├──  post.validator.ts
│   │       └──  user.validator.ts
│   ├──  app
│   │   └──  index.ts
│   ├──  config
│   │   ├──  helmet.config.ts
│   │   └──  logger.config.ts
│   ├──  prisma
│   │   ├──  db
│   │   ├──  db.seed.ts
│   │   └──  schema.prisma
│   ├──  public
│   │   ├──  css
│   │   ├──  favicon.ico
│   │   ├──  fonts
│   │   ├──  img
│   │   └──  js
│   └──  server.ts
├──  tests
│   ├──  e2e
│   ├──  fixtures
│   ├──  integration
│   └──  unit
│       └──  api.test.ts
├──  .env
├──  .eslintignore
├──  .eslintrc.js
├──  .gitattributes
├──  .gitignore
├──  .prettierrc.js
├──  CHANGELOG.md
├──  CODE_OF_CONDUCT.md
├──  CONTRIBUTING.md
├──  LICENSE
├──  jest.config.js
├──  package-lock.json
├──  package.json
├──  README.md
├──  SECURITY.md
└──  tsconfig.json

Linting

License

MIT