LogoLogo
  • Overview
    • How to obtain an API key?
  • Webhooks
    • About Webhooks
    • Quickstart Guide
      • Set up your server
      • Creating a webhook
      • Configure your server
      • Review your webhooks
      • Secure webhooks
    • Webhook events
      • About events
      • Event List
    • Troubleshooting
  • REST API
    • Overview
      • Current Version
      • Authentication
      • Pagination
    • Quickstart Guide
      • Find the API key
      • Playground
    • API References
      • Rides
      • Search
      • Customers
      • Drivers
      • Webhooks
      • Auth
    • Errors
      • Error codes
    • Troubleshooting
Powered by GitBook
On this page

Was this helpful?

  1. Webhooks
  2. Quickstart Guide

Configure your server

Learn to set up a server to manage incoming webhooks.

PreviousCreating a webhookNextReview your webhooks

Last updated 3 years ago

Was this helpful?

Now that our webhook is ready to deliver messages, we'll set up a basic Express server to handle incoming payloads.

Writing the server

We want our server to listen to POST requests, at /webhook, because that's where we told EverTransit our webhook URL was. Because we're using ngrok to expose our local environment, we don't need to set up a real server somewhere online, and can happily test out our code locally.

Let's go inside the project created in the section and set up a little Express app to do something with the information. Open the index.js file and copy and paste for our initial setup which might look like this:

index.js
const express = require('express');
const PORT = 3000;

const app = express();

app.use(express.json());

app.post('/webhook', (req, res) => {
    const body = req.body;
    console.log(body);
    return res.sendStatus(200);
});

app.listen(PORT, () => {
    console.log(`Listening at port ${PORT}`);
});

Start this server up executing node index.js from your terminal.

Since we set up our webhook to listen for ride.created events, go ahead with your dispatch and create a new ride for testing purposes; you can cancel it later. Once you've created it, switch back to your terminal. You should see something like this in your output:

Success! You've successfully configured your server to listen for webhooks. Your server can now process this information in any way it sees fit.

Setup your server