Custom REST endpoints

default discord avatar
BrettBedarf
last year
1 1

Is it possible to add custom REST endpoints?

  • discord user avatar
    denolfe
    Payload Team
    last year

    Hey @BrettBedarf, good question. Since Payload simply takes your express app as a parameter, you still have full access to it to add any additional functionality as needed. Here is an example server.ts that is generated runningnpx create-payload-app. You would simply add your additional functionality after the payload.init call.

    import express from 'express';
    import payload from 'payload';
    
    require('dotenv').config();
    const app = express();
    
    // Initialize Payload
    payload.init({
      secret: process.env.PAYLOAD_SECRET,
      mongoURL: process.env.MONGODB_URI,
      express: app,
    })
    
    // Add your own express routes here
    
    app.listen(3000);

    Hopefully, that answers your question. Let me know if you have any follow up questions 👍

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.