Skip to main content

Add a Route

Define an API route

Route example

Here is a sample model that you can use as a start up

let express = require("express");
let controller = require("../controller/tourController");
let authControler = require("../controller/authControler");
let routes = express.Router();
let logMiddleware = require("../middleware/logger");
const Joi = require("joi");
const validator = require("express-joi-validation").createValidator({});
const addSchema = Joi.object({
title: Joi.string().required().min(3),
headerPhoto: Joi.required(),
images: Joi.required(),
excluded: Joi.array().required(),
});
//CRUD
routes.use("*", logMiddleware);
routes.post("/", validator.fields(addSchema), controller.addData); // CREATE
routes.get("/", controller.getData); // READ
routes.patch("/:id", controller.updateData); //UPDATE
routes.delete("/:id", controller.deleteData); // DELETE
module.exports = routes;

Docs reference

info

A more detailed model with virtual methods and model references can be located at /docs/api-reference/Model.js from the project root

Controller development

Security

Add controller security