This API is using a json file to store the data locally. It's based on the 4 CRUD actions: Create, Read, Update, Destroy.
All four API functions take a key
as the first parameter.
create(key, data);
Use the create function to add new data to your database.
key
A string which represents the resource being created.
data
An object which represents one of the resources being created.
The data
object with an auto-incremented ID.
create("books", { title: "The Da Vinci Code" });
read(key[, id]);
Use the read function to access data in your database.
key
A string which represents the resource being created.
id - optional
An optional ID. If no ID is supplied, the entire array of objects is returned. If an ID is supplied, only the object with that ID is returned.
The array of data at that resource or the single object with the supplied ID.
read("books");
read("books", 2);
create(key, data);
Use the update function to update existing data in your database.
key
A string which represents the resource being created.
data
An object which represents the resource being updated.
The updated data
object.
const book = read("books", 1);
book.title = "Harry Potter";
update("books", book);
destroy(key, id);
Use the destroy function to delete some data in your database.
key
A string which represents the resource being created.
id
An ID of an object in the database.
The new array without the object with the supplied ID.
destroy("books", 1);