2.0.9 • Published 1 year ago

freeclimb-request-types v2.0.9

Weekly downloads
22
License
MIT
Repository
github
Last release
1 year 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

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.8

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago