2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 11:29:00 +00:00
books/docs/client/index.md
Rushabh Mehta 328a9de7d4 💥 frappejs
2018-01-16 11:39:17 +05:30

1.4 KiB

Client

Frappe.js comes with built in single-page-application (SPA) with routing, views, list and form objects.

In building the client, you can use the REST API to query data, and use the models and controllers declared in your module.

You can use the same document API in the client as in the server, the only difference being that the data will be fetched via REST API in the background.

Routing

Views

Starting

You can setup your client by setting up the server and then importing your controllers with require

Example

const client = require('frappejs/frappe/client');

client.start({
	server: 'localhost:8000',
	container: document.querySelector('.container'),
}).then(() => {
	const todo = require('frappejs/frappe/models/doctype/todo/todo.js');
	frappe.init_controller('todo', todo);

	// ....
});

REST Client

Frappe.js comes with a built in REST client so you can also use REST as a database backend with the Frappe.js API

Create, Read, Update, Delete

You can manage documents, using the same Document API as if it were a local database

Example

await frappe.init();
await frappe.init_db('rest', {server: 'localhost:8000'});

let doc = await frappe.get_doc({doctype:'ToDo', subject:'test rest insert 1'});
await doc.insert();

doc.subject = 'subject changed';
await doc.update();

let data = await frappe.db.get_all({doctype:'ToDo'});