apis.do

2.3.3 • Public • Published

APIs.do - Driv.ly Workers framework

Important note:

If you don't link a CTX service worker, the API will default to fetching data from ctx.do. This means that the IP address and CF-Ray-Id headers will be incorrect for the request. If you want to use the correct IP address and CF-Ray-Id headers, you must link a CTX service worker.

Example

This example shows off the following features:

  • Automatic API documentation
  • Link generation
  • Query parameter modification
  • Query modification for multiple values (cities, zip codes, credit scores, etc.)
import { API, json, requiresAuth, modifyQuery, modifyQueryMultiple, schemaGen } from 'apis.do'

const api = new API({
  name: 'domain.do',
  description: '🤖 API'
}, {
  examples: {
    createVehicle: '/hello/0'
  }
})

api.get('/:hello/:worldNumber?', req => {
  return {
    links: {
      self: req.url,
      next: modifyQuery(req.url, { worldNumber: req.params.worldNumber + 1 }),
      'Create Plan By City': modifyQueryMultiple(req.url, 'zip', req.ctx.cities)
    },
    data: {
      hello: req.params.hello,
      worldNumber: req.params.worldNumber
    }
  }
}, {
  description: 'Hello world',
  parameters: {
    hello: 'string',
    worldNumber: 'number'
  },
  response: schemaGen({ hello: '', worldNumber: 0 })
})

export default {
  fetch: api.fetch
}

Request properties

Most of the properties are self-explanatory, but here are some modifications to the request object provided by itty-router:

  • request.user - The user object from ctx.vin
  • request.ctx - The context object from ctx.vin
  • request.waitUntil - The waitUntil function exposed by Cloudflare Workers
  • request.params - The params object from itty-router
  • request.query - The query object from itty-router
  • request.body - The body object from itty-router

Drivly Open – Accelerating Innovation through Open Source

Our Drivly Open Philosophy has these key principles:

  1. Build in Public
  2. Create Amazing Developer Experiences
  3. Everything Must Have an API
  4. Communicate through APIs not Meetings
  5. APIs Should Do One Thing, and Do It Well

🚀 We're Hiring!

Driv.ly is deconstructing the monolithic physical dealership into simple APIs enabling anyone to buy and sell cars online, and we're funded by some of the biggest names in automotive and finance & insurance

Our entire infrastructure is built with Cloudflare Workers, Durable Objects, KV, PubSub, R2, Pages, etc. If you love the Cloudflare Workers ecosystem as much as we do, we'd love to have you join our team!

Readme

Keywords

none

Package Sidebar

Install

npm i apis.do

Homepage

apis.do

Weekly Downloads

1

Version

2.3.3

License

MIT

Unpacked Size

214 kB

Total Files

9

Last publish

Collaborators

  • nathanclevenger