DEV Community

Discussion on: ⚡ Add a GraphQL Server to a RESTful Express.js API in 2 Minutes

stemmlerjs profile image
Khalil Stemmler Author

Scary, secret things... Just kidding.

Usually, my router is where I delegate chunks of the API off to appropriate sub-routers to then get more detailed with how things get done :)

I also usually version my REST APIs (like v1Router).

import express from 'express'
import { userRouter } from '../../../../modules/users/infra/http/routes';
import { memberRouter, commentRouter } from '../../../../modules/forum/infra/http/routes';
import { postRouter } from '../../../../modules/forum/infra/http/routes/post';

const v1Router = express.Router();

v1Router.get('/', (req, res) => {
  return res.json({ message: "Yo! we're up" });

v1Router.use('/users', userRouter);
v1Router.use('/members', memberRouter);
v1Router.use('/posts', postRouter);
v1Router.use('/comments', commentRouter);

export { v1Router } // or { router }, like the rest of the code.
Enter fullscreen mode Exit fullscreen mode

You can see this code in the project it's from here, btw.

paul_melero profile image
Paul Melero

Appreciated ❤️