Skip to content

πŸ”° A RESTful-API starter, built with TypeScript & Prisma.

License

Notifications You must be signed in to change notification settings

BCIT-DDC/node-ts-restful-api-starter

Repository files navigation

Node Express RESTful API Starter (TS)

Introduction

Getting Started

1. Download starter and install dependencies

Clone this repository:

git clone [email protected]: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

About

πŸ”° A RESTful-API starter, built with TypeScript & Prisma.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published