Concepts overview
Codehooks.io simplifies and speed up system integration and API development by combining serverless JavaScript functions and fast Database persistence with a coherent and well documented API. Applications are easily deployed to the secure and scalable Codehook managed cloud.
Forget about cluttering servers, databases, infrastrucure and protocols - just focus on what matters.
Codehooks includes these main features:
- Studio - Developer friendly web based tools for managing both data and code
- Node.js and JavaScript - Same language for frontend and backend development (ES6 and Typescript)
- NPM - Node.js package manager (npm) integration
- Node.js Express - API development with Express-like API
- NoSQL - Document database with Mongodb-like API
- Key-Value - Key-Value database with a Redis-like API (subset)
- Worker Queues - Persistent queues with worker functions
- Background jobs - Cron jobs with scheduled worker functions
- CLI - Powerful Command Line Interface (CLI) for productivity and DevOps/CI support
Read on to learn more about how development with Codehooks.io can simplify and add value to your project and team.
Unless you've already have, please read the quick start first to learn how to install the CLI, and how to sign up/login to create your first Codehooks project.
Codehooks main concepts
Project
A project is the top level concept in Codehooks. A project is owned by an account (private or company) and contains one or multiple "spaces" with your deployed code, data and access credentials in an isolated and secure unit. You can create multiple projects within your account and you can join/invite others to a project. An example project structure is shown below:
- [email protected] (private or corporate account owner)
- customers (project name)
- dev (development space)
- Database instance
- Security settings (API tokens, environment secrets, IP filters ...)
- Source code (deployed version 1.1.12)
- Developers ([email protected], [email protected])
- prod (production space)
- Database instance
- Security settings (API tokens, environment secrets, IP filters ...)
- Source code (deployed version 1.1.0)
- Developers ([email protected], [email protected])
- dev (development space)
- salesdb (project name for another project)
- ...
- customers (project name)
Projects are created with the CLI command coho create
(CLI docs here)
You can also manage your projects and spaces using the account user interface at https://account.codehooks.io.
The project application source code
A Codehooks application follows the familiar principles and best practices of modern JavaScript development. A project directory typically contains:
- An
index.js
file for the application main entry code - A
package.json
file with library dependencies - A
config.json
file with project information
We also recommend that you add source control (GIT) to manage your versions and branches. Typically this will be a git repo with branches that are deployed to various spaces.
A minimal example
The following example shows a complete process for creating a new project with an application that is deployed to the Codehooks serverless cloud.
First, create and setup a new project application:
coho create example
cd example
npm init --yes
npm install codehooks-js --save
After running the commands your project directory contains these files:
.
├── config.json
├── index.js
├── node_modules
├── package-lock.json
└── package.json
If you inspect the source file index.js you'll see the default generated application code:
/*
* Auto generated Codehooks (c) example
*/
import {app, crudlify} from 'codehooks-js'
// test route for https://<PROJECTID>.api.codehooks.io/dev/
app.get('/', (req, res) => {
res.send('CRUD server ready')
})
// Use Crudlify to create a REST API for any collection
crudlify(app)
// bind to serverless runtime
export default app.init();
We can now deploy the application (in our case example-4g9p) to the cloud with the CLI command coho deploy
(CLI docs here).
coho deploy
# Server output example
Project: example-4g9p Space: dev
Deployed Codehook successfully! 🙌
After deployment we can inspect the application details with the coho info
command, in this example showing our default space dev
with its base endpoint URL and access token(s):
coho info --examples
Project name: example-4g9p
Team: YOUR-NAME (personal account)
API endpoint: https://example-4g9p.api.codehooks.io/dev/*
Spaces:
┌──────────────┬────────────────────────────────────────────┬──────┬──────┐
│ Name │ Tokens │ Jwks │ Env │
├──────────────┼────────────────────────────────────────────┼──────┼──────┤
│ dev (active) │ a77926ca-xxx-yyyy-zzzzz-14eee564f8d5 (RW) │ │ │
└──────────────┴────────────────────────────────────────────┴──────┴──────┘
After successful deployment we can test our application endpoint with curl. This minimal example and test shows that our application is deployed to a secure endpoint and returns the expected result:
curl -X GET 'https://example-4g9p.api.codehooks.io/dev' \
-H 'x-apikey: a77926ca-xxx-yyyy-zzzzz-14eee564f8d5'
# API output example from server
CRUD server ready
Project spaces
A project space is a self-contained and isolated bundle of code, datastores and security settings within a specific project. All projects have a default space called dev
which is created automatically when you add a project. You create new spaces with the coho add
command (CLI docs here). You can easily switch between different project spaces with the coho use
command (CLI docs here). Spaces can also have restricted access (team ADMINs only), which is convenient for production deployments.
For example, in your project you want to have isolated development, testing and production spaces.
Project-X
└── dev
├── source code (git branch dev)
├── security settings & env variables
└── data stores
└── test
├── source code (git branch test)
├── security settings & env variables
└── data stores
└── prod (restricted)
├── source code (git branch prod)
├── security settings & env variables
└── data stores
Deploy your application to the Codehooks serverless cloud
Each project space is created as an isolated resource group in the Codehooks cloud.
For example, the coho add prod
command creates a project space called prod
. By switching to the space with the coho use prod
command, this space is now the active (changed in the config.json project file).
On deployment with the coho deploy
command, the current version of your application source code is packed and distributed as a serverless runtime to the prod space in the Codehook cloud.
Similarily, switching to another space, e.g. by using the coho use dev
, sets the dev space as the active, and coho deploy
will deploy the application to the active dev space.
This is a powerful feature, which effectively enables you to run multiple versions of your application with separate settings, environments and data stores.
Built in Datastores
Persisting, querying and manipulating data is essential in any application. Codehooks comes with a built in datastore that supports streaming NoSQL and Key-Value operations. No need to think about drivers and protocols, it's built directly into the Codehooks APIs.
- NoSQL object data are accessed with the standard Database API.
- Key-Value data are accessed with the standard Key-Value API
Data wrangling
Using the CLI command coho import
, you can easily import any CSV or JSON file into a datastore.
Furthermore, the coho query
command lets you query and transform data in advanced ways.
coho import -c stocks -f ~/Downloads/all_stocks_5yr.csv
coho query stocks --query 'Name=GOOG&open>10' --limit 2 --table
┌───────────┬───────────┬───────────┬───────────┬───────────┬───────────┬───────────┬───────────┐
│ date │ open │ high │ low │ close │ volume │ Name │ _id │
├───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤