simple online nosql database database with REST API and MongoDB queries
  • Features
  • Docs
  • Blog
  • Templates
  • Pricing
  • Contact
  • Sign Up
  • Log In

Blog

 The latest news and articles about restdb.io  

Database templates!
Don't forget to visit our template catalog! It's the fastest way to get up and running with a restdb.io database. View templates »

Stay in the loop with Codehooks and Slack

by Jon Erik Solheim
|
Integrations|Features|Tutorials|API|
  • Share on Facebook
  • Tweet
  • Add to Pocket
  • Share on LinkedIn
  • Send email

The new restdb.io feature, Codehooks,  lets you execute JavaScripts directly in your database.

This feature opens up an array of cool scenarios for your application.  One of them is to integrate your database with slack.com.

Slack seems to be every team’s favorite collaboration platform now. If you’re not using this great tool already, I would suggest you give it a try. It can practically eliminate the need for sending internal (non-important) emails, and introduces a more human touch to your team information flow.

That’s why it makes sense to let your database talk to Slack, instead of you logging on to your database admin, all the time, to see what’s going on.

This blog post shows you how you can create a JavaScript Codehook to feed your Slack with important stuff that happens inside your database.

JavaScript Codehooks

Codehooks are small JavaScript functions that executes inside the scope of your database. As their name indicates, your "code" “hooks” into data REST verbs (like POST and PUT) and let you perform custom logic, network calls and much more.

The generic format of a Codehook looks like this:

var beforePOST = function(req, res) {
    res.end();
}

You'll find the code editor for the Codehooks under your Collection settings (Codehook tab), shown in the screen shot below:

editor

Network calls from a Codehook

Codehooks can perform network calls by using the request API.  You can use this API to call any HTTP based API, including Slack. 

We’ve also made it even simpler by providing a pre defined slack API call.  All you need to do in the Codehook is to call:

slack(options, callback);

The options parameter contains data for the Slack message. The example below shows how we hook into a POST operation and send a message to Slack about the event:

function beforePOST(req, res){
    var slackhookurl = "https://hooks.slack.com/services/IUYERKJ/KJH678JHG/987sdfkhj8976sdf";
    var who = req.hint['#usersession'].email || 'API';
    var slackopt = {
        "message": `${who} created a new Customer: ${req.body.name} :smile:`,
        "slackhookurl": slackhookurl,
        "channel": "#projectx"
    }
    slack(slackopt, function(body){
        res.end();
    });
}

Set up your Slack URL

In order to call Slack from your Codehook, you must create an Incoming Webhook URL. Visit this url to get started https://api.slack.com/incoming-webhooks. Click on the link highlighted in the screen shot below:

incoming webhook

Follow the instructions and generate a new Webhook URL from Slack and apply this in your code to connect properly.

After a successful connection your Slack gets populated with useful data events like the example below:

slack

This blog post has hopefully given you an idea of how you can integrate events from your database and send them to Slack. Codehooks are a powerful tool that lets you create custom logic and perform networked integration with ease.

Keep your team in the loop with Codehooks and Slack, start experimenting with your own Codehooks today.

Read more about Codehooks in the docs here: https://restdb.io/docs/codehooks
  • Share on Facebook
  • Tweet
  • Add to Pocket
  • Share on LinkedIn
  • Send email

All Posts


Search

Topics

  • API
  • Authentication
  • Case study
  • Features
  • Howto
  • Integrations
  • Newsletter
  • Productivity
  • Prototyping
  • Tutorials
  • User

restdb.io is a fast and simple NoSQL cloud database service. With restdb.io you get schema, relations, REST API and an efficient multi-user admin UI for working with data.

Our customers use it for backends, business databases, API-first CMS, data collection and much more. It is easy to get started with the free development plan.

Start Building »

  • Site Links
  • Home Page
  • About Us
  • Contact
  • Blog
  • Templates Catalog
  • Cloud Service
  • Features
  • Pricing
  • Terms & Conditions
  • Privacy Policy
  • Sign Up »
  • Documentation
  • Overview
  • Getting Started
  • Coding against the API
  • Utils
  • Security and Admin
© 2025 restdb.io