API Reference

February 21, 2026 · View on GitHub

Import

// ESM (npm)
import jscrudapi from 'js-crud-api';

// Browser (IIFE)
// <script src="min.js"></script> → jscrudapi available globally

Initialization

const jca = jscrudapi(baseUrl, config);
ParameterTypeDescription
baseUrlstringPHP-CRUD-API entry point URL (e.g. 'http://localhost/api.php')
configobjectOptional configuration passed to fetch() (headers, credentials, etc.)

CRUD functions

All functions return a Promise.

list(table, conditions)

Lists records from a table.

ParameterTypeDescription
tablestringTable name
conditionsobjectOptional conditions (see Conditions)

read(table, ids, conditions)

Reads one or more records by ID.

ParameterTypeDescription
tablestringTable name
idsnumber | string | ArrayID(s) to read. E.g. 1, '1,2', [1, 2]
conditionsobjectOptional conditions

create(table, data)

Creates one or more records.

ParameterTypeDescription
tablestringTable name
dataobject | ArrayData to insert. A single object or an array of objects

update(table, idOrList, data)

Updates one or more records.

ParameterTypeDescription
tablestringTable name
idOrListnumber | string | ArrayID(s) to update
dataobject | ArrayNew data

delete(table, idOrList)

Deletes one or more records.

ParameterTypeDescription
tablestringTable name
idOrListnumber | string | ArrayID(s) to delete

Authentication functions

Implements PHP-CRUD-API DBAuth.

FunctionParametersDescription
register(username, password)string, stringRegister a new user
login(username, password)string, stringLog in
password(username, password, newPassword)string, string, stringChange password
logout()Log out
me()Get current user info

Conditions

Conditions are passed as an object. Values can be string, number or Array.

Filtering

jca.list('table', { filter: 'field,eq,value' });
jca.list('table', { filter: ['field1,eq,v1', 'field2,gt,v2'] });       // AND
jca.list('table', { filter: 'field1,eq,v1', filter1: 'field2,eq,v2' }); // OR

Modifiers: cs, sw, ew, eq, lt, le, ge, gt, bt, in, is. Negate with n prefix (e.g. neq).

Joining

jca.list('table', { join: 'other' });
jca.list('table', { join: ['t1', 't2'] });         // path: table>t1>t2
jca.list('table', { join: [['t1'], ['t2']] });      // paths: table>t1 and table>t2

Pagination and size

jca.list('table', { page: '1,50' });
jca.list('table', { size: 10 });

Column selection

jca.list('table', { include: 'field1,field2' });
jca.list('table', { exclude: ['field1'] });

Ordering

jca.list('table', { order: 'field,desc' });
jca.list('table', { order: ['field1,desc', 'field2'] });

Error handling

All functions reject the Promise on error with a { code, message } object.

CodeSource
-1JavaScript network error (fetch)
OthersPHP-CRUD-API error codes

Current limitations

  • Endpoints not implemented: /openapi, /geojson, /columns, /status/ping
  • Only DBAuth is supported (not JWT or Basic Auth)
  • No encodeURIComponent encoding on condition values