Like what we’re doing? Star us on GitHub!

Custom REST endpoints

BrettBedarf
11 months ago
1 1

Is it possible to add custom REST endpoints?

  • denolfe
    Payload Team
    11 months ago

    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
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More