Reference
API Reference
A complete reference for every Crescent.js method.
Convention
Core methods are called on the
crescent instance, database methods on crescent.db, and authentication methods on crescent.auth.page()
Creates a new page container.
js
const page = crescent.page({
page_id: 'home',
page_title: 'Home',
page_description: 'Home page',
size: { height: 900, width: 1440 }
});| Property | Type | Required | Description |
|---|---|---|---|
page_id | string | yes | Unique identifier |
page_title | string | no | Browser tab title |
page_description | string | no | Meta description |
size | object | yes | { height, width } in pixels |
object()
Creates a container for layers.
js
crescent.object({
object_id: 'header',
size: { height: 80, width: 600 },
page_position: { x: 0, y: 0 }
});| Property | Type | Required | Description |
|---|---|---|---|
object_id | string | yes | Unique identifier |
size | object | yes | { height, width } |
page_position | object | no | Cartesian { x, y } |
page_index | number | no | Stacking order on the page |
bg_layer | string | no | Layer rendered behind the object |
object_enabled | boolean | no | Whether the object renders (default true) |
layer()
Creates a visual element. Requires layer_type and layer_id.
js
crescent.layer({
layer_type: 'text',
layer_id: 'title',
text: 'Hello',
size: 32,
colour: '0,0,0'
});| Property | Type | Required | Description |
|---|---|---|---|
layer_type | string | yes | text, image, shape, input |
layer_id | string | yes | Unique identifier |
text | string | no | Text content (text and shape layers) |
size | number | object | no | Font size for text, or { height, width } for image/shape/input |
colour | string | no | Colour as 'r,g,b' (text and shape layers) |
image_location | string | no | Image URL (image layers) |
layer_vertices | number | no | Number of sides, e.g. 4 for a rectangle (shape layers) |
input_method | string | no | Input style, e.g. 'text box' (input layers) |
function()
Defines a reusable backend function.
js
crescent.function({
function_id: 'add',
params: ['a', 'b'],
body: function (a, b) {
return a + b;
}
});
crescent.get_function('add').call(2, 3); // 5| Property | Type | Required | Description |
|---|---|---|---|
function_id | string | yes | Unique identifier |
params | string[] | no | Argument names |
body | function | yes | Executes when called |
api_make()
Creates an HTTP server with endpoints.
js
const api = crescent.api_make({
api_id: 'main',
port: 3000
});
api.add_endpoint('GET', '/users', function (req, res) {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ users: [] }));
});
api.start();| Method | Description |
|---|---|
add_endpoint(method, path, handler) | Registers a route. method is GET, POST, PUT, or DELETE; handler receives Node.js req and res |
start() | Starts listening on the configured port |
api_call()
Makes an outgoing HTTP request.
js
const request = crescent.api_call({
api_call_id: 'fetch_users',
url: 'https://api.example.com/users',
method: 'GET'
});
request.call().then(function (data) {
console.log(data);
});Database Methods
Called on crescent.db. Data is stored in collections.
| Method | Description |
|---|---|
create(collection) | Creates a new collection |
insert(collection, doc) | Inserts a record and returns it with its _id |
insert_many(collection, docs) | Inserts multiple records at once |
find(collection, query) | Returns all records matching a query |
find_one(collection, query) | Returns the first record matching a query |
find_by_id(collection, id) | Finds a record by _id |
update(collection, query, updates) | Updates all records matching a query |
update_one(collection, query, updates) | Updates the first record matching a query |
delete(collection, query) | Deletes all records matching a query |
Auth Methods
Called on crescent.auth.
| Method | Description |
|---|---|
signup().register(username, email, password) | Creates a new user account |
login().authenticate(username, password) | Validates credentials, returns the user, a session token, and a cookie header |
login().verify_session(token) | Verifies a session token |
password.hash(password) | Returns { hash, salt } |
password.verify(password, hash, salt) | Checks a password against a stored hash |
password.check_strength(password) | Returns a strength score and label |
oauth().add_provider(name, config) | Configures an OAuth provider |
oauth().get_authorize_url(provider) | Builds the authorization URL for a provider |
Page Methods
| Method | Description |
|---|---|
add_object(object) | Adds an object to the page |
set_object_position(object_id, x, y) | Sets an object's cartesian position |
render() | Renders the page into the DOM |
Next Steps
- Backend Guide — functions, loops, and APIs in action
- Deployment Guide — ship your app