Overview
Codehooks: Integrate and Automate everythingโ
Codehooks provides powerful tools for developers to build, connect, and process APIs with ease. Create projects using our intuitive command line interface or web-based admin UI. A Codehooks.io project contains multiple isolated spaces - complete self-contained environments with their own database, settings, and code.
The codehooks-js
library is the foundation for all Codehooks JavaScript development, offering a comprehensive set of 7 specialized APIs that accelerate development, streamline data integration, and simplify data processing. Explore each capability below to see how Codehooks can improve your development experience.
If you're like most developers (i.e. smart and lazy ๐), we've added a ChatGPT and LLM Prompt you can use to kickstart new projects. The prompt itself is worth looking at to get an overview of the features of the codehooks-js library. Our new MCP Server implementation has this prompt built-in.
To deploy code (and much more), you use the Codehooks CLI tool:
npm install codehooks -g
Code editing and deployment will also soon be available in the web based UI.
API developmentโ
Get a flying start with an automatic CRUD REST API
myproject-fafb
. Under the hood, Codehooks deploys an automatic REST API which is made up of the following really short - but complete application code:import {app} from 'codehooks-js'
// Use Crudlify to create a REST API for any database collection
app.crudlify()
// bind to serverless runtime
export default app.init();
const URL = 'https://myproject-fafb.api.codehooks.io/dev/orders';
response = await fetch(URL+'?status=OPEN', /* options */)
const result = await response.json()
NoSQL and Key-Value Datastoresโ
Easy database API inspired by MongoDB
import {app, datastore} from 'codehooks-js'
// REST API route
app.get('/sales', async (req, res) => {
const conn = await datastore.open();
const query = { status: "OPEN" };
const options = { sort: { date: 1 } }
conn.getMany('orders', query, options).json(res); // stream JSON to client
})
// bind to serverless runtime
export default app.init();
Speed up your application with a Key-Value cache
ttl
option.import {app, datastore} from 'codehooks-js'
// REST API route
app.post('/cacheit', async (req, res) => {
const conn = await datastore.open();
const opt = {ttl: 60*1000};
await conn.set('my_cache_key', '1 min value', opt);
res.send('Look dad, I have my own cache now!');
})
// bind to serverless runtime
export default app.init();
Background Jobsโ
CRON expressions + your function keeps running
In the simple example below, the CRON expression */5 * * * *
will trigger a JavaScript function each 5 minutes.
import app from 'codehooks-js'
// Trigger a function with a CRON expression
app.job('*/5 * * * *', (_, job) => {
console.log('Hello every 5 minutes')
// Do stuff ...
job.end()
});
export default app.init();
Queuesโ
Scale workloads with queues and worker functions
Check out the example below, where a REST API request starts a complex task by adding it to the Queue for later processing.
import { app, Datastore } from 'codehooks-js'
// register a Queue task worker
app.worker('ticketToPDF', (req, res) => {
const { email, ticketid } = req.body.payload;
//TODO: implement code to fetch ticket data, produce PDF
// and send email with attachment using Mailgun, Sendgrid or Amazon SES
// ...and implement error handling
res.end(); // done processing queue item
})
// REST API
app.post('/createticket', async (req, res) => {
const { email, ticketid } = req.body;
const conn = await Datastore.open();
await conn.enqueue("ticketToPDF", { email, ticketid });
res.status(201).json({"message": `Check email ${email}`});
})
export default app.init();
Reliable Workflowsโ
Build reliable stateful workflows
The example below shows a simple workflow that processes customer onboarding with email validation.
import { app } from 'codehooks-js';
const workflow = app.createWorkflow('customerOnboarding', 'Customer signup and email validation', {
START: async function (state, goto) {
state = { email: state.email, validated: false };
await sendWelcomeEmail(state.email);
goto('waitForValidation', state);
},
waitForValidation: async function (state, goto) {
if (state.validated) {
goto('complete', state);
} else {
wait({wait_message: 'Waiting for subflow to complete'});
}
},
complete: function (state, goto) {
state.status = 'completed';
goto(null, state); // workflow complete
}
});
// Start workflow from REST API
app.post('/start-onboarding', async (req, res) => {
const result = await workflow.start({ email: req.body.email });
res.send(result);
});
File System & Blob storageโ
Serve any document or file content
dev
space (environment) of the project. You can publish documents and files in two ways. Use the file-upload CLI command for mass uploads of files/directories:$ coho file-upload --projectname 'myproject-fafc' --space 'dev' --src '/somedir/' --target '/myblobs'
$ coho deploy
import {app} from 'codehooks-js'
// serve the assets directory of the deployed project source code
app.static({directory: "/assets"})
// serve a direcory of Blob storage files
app.storage({route:"/documents", directory: "/myblobs"})
// CRUD REST API
crudlify(app)
// bind to serverless runtime
export default app.init();
Data Aggregationโ
Easy to use data aggregation format
import { app, Datastore, aggregation } from 'codehooks-js'
... // collapsed code
const spec = {
$group: {
$field: "month",
$max: ["sales", "winback"],
$sum: "sales"
}
}
const db = await datastore.open();
const dbstream = db.getMany('salesData');
const result = await aggregation(dbstream, spec)
... // collapsed code
{
"oct": {
"sales": {
"max": 1477.39,
"sum": 1234.05
},
"winback": {
"max": 22.0
}
},
"nov": {
"sales": {
"max": 2357.00,
"sum": 5432.00
},
"winback": {
"max": 91.0
}
},
}
Next Stepsโ
Read this far? Great ๐
It's time to get your feet wet ๐ฆ. Why don't you start thinking about how codehooks' toolbox can help you build your solution. You can get started with the quickstart for developers or just sign up and create your project and space using the web UI. You can easily upload some CSV data and immediately test your new API.
The documentation or tutorials are great places to start. If you need more help, feel free to contact us on the chat.