Skip to content

use cambria to migrate API requests as express middleware

License

Notifications You must be signed in to change notification settings

inkandswitch/cambria-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cambria Express

This is a simple proof of concept of what it might look like to use cambria to version rest calls via an express plugin.

A proper implementation would be far more full featured offering different lenses for input and output across a broad range of APIs.

The example code explains this best

The idea is that you only need to implement a single version of the REST api. If you give CambriaExpress lenses between this version and others it can export them all, lensing input data before calling the canonical api, then reverse lensing the response back into the other format.

const migrations = [ ..., { from: "v1", to: "v2", lenses: [...] ]

const app = express()
app.use(express.json())
app.use("/api", cambriaExpress({ version: "v2", action: "task", migrations }))

app.get("/api/v2/task/:id", (req,res) => {
  //...
})

About

use cambria to migrate API requests as express middleware

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published