2.0.9 • Published 2 years ago

freeclimb-request-types v2.0.9

Weekly downloads
22
License
MIT
Repository
github
Last release
2 years ago

freeclimb-request-types

freeclimb-request-types is a package adding typescript support for freeclimb application webhooks.

Installing

npm isntall freeclimb-request-types

or

yarn install freeclimb-request-types

Getting Started

import express, { Request } from 'express';
import {InboundCallBody} from "freeclimb-request-types";
import bodyParser from 'body-parser';

const app = express()
app.use(bodyParser.json());
const port = 3000

// Tells the code that the request body will of InboundCallBody type
app.post('/callEntry', (req: Request<{}, {}, InboundCallBody>, res) => {
  req.body.callId; // $ExpectType string

  res.send([{
    Say: {
      text: `The number you called is ${req.body.to}`
    }
  }])
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

in addition type guards are also available

import {isInboundCall} from "freeclimb-request-types";

app.post('/callEntry', (req, res) => {

  if(isInboundCall(req.body)) {
    res.send([{
      Say: {
        text: `The number you called is ${req.body.to}`
      }
    }]);
  } else {
    res.status(400).send('Invalid request');
  }
});
2.0.9

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.8

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago