GithubHelp home page GithubHelp logo

frappe-client-js's Introduction

frappe-client-js

CI Status npm License

Client Utility for frappe framework

Install


npm install frappe-client

Usage


Importing

import { FrappeClient } from 'frappe-client';
// or
const { FrappeClient } = require('frappe-client');

Creating a client

const getHeaders = async () => ({
	Authorization: 'Bearer ...',
});

// includes all the clients (api, etc)
const frappe = new FrappeClient(baseURL, getHeaders);

Frappe Resource Calls (Direct Doctype Access)

const doctype = frappe.Resource('Doctype');

doctype.list({ filters, fields, ...more }).then(res => console.log(res.data)); // get list of documents
doctype.create({ ...data }).then(res => console.log(res.data)); // create a document
doctype.get('docname').then(res => console.log(res.data)); // get a document

const document = doctype.getDoc('docname'); // get a Document object

Resource Call Example

(async () => {
	const doctype = frappe.Resource('Doctype');
	const response = await doctype.list({ filters, fields, ...more });
	console.log(response.data);
})();

Frappe Document Acces

const doctype = frappe.Resource('Doctype');

// get a Document object
const document = doctype.getDoc('docname');
// or
const document = frappe.Document('Doctype', 'docname');

document.get().then(console.log); // get data from server and add it to cache
document.update({ ...data }).then(console.log); // update data and update to cache
document.delete().then(console.log); // delete data and remove from cache
console.log(document.getDocument()) // get data from cache

Document Call Example

(async () => {
	const doctype = frappe.Resource('Doctype');
	const document = frappe.Document('Doctype', 'docname');
	const response = await document.get();
	console.log(response);
})();

Frappe Remote Method Calls

// we can access the methods scoped to the app
const app = frappe.Method('appName'); // get a Method object with the appname

app.get(methodPath, args); // GET request
app.post(methodPath, args); // POST request
app.put(methodPath, args); // PUT request
app.delete(methodPath, args); // DELETE request
app.head(methodPath, args); // HEAD request
app.options(methodPath, args); // OPTIONS request

Method Call Example (RPC)

const app = frappe.Method('appName');
app
	.post('module_name.path.method_name', {
		arg1: 'ARG!',
		arg2: 'ARG!!',
	})
	.then(console.log);

Testing


npm test

License


The MIT License. See the license file for details.

frappe-client-js's People

Contributors

tamil-03 avatar

Watchers

 avatar  avatar

frappe-client-js's Issues

Use generics

I see that most documents are represented as string | number | object, would it be possible to update the client to use generics to get better document types?

I don't mind implementing this and creating a pull request, if that's easiest.

Thanks!

All requests are logged

Hi there, thanks for creating this client! I've been using it for a project, and I've noticed that every request is logged to the console. I see this is because of src/api/client.ts:68. Would it be possible to remove this line, or perhaps put it behind a debug environment variable?

I wouldn't mind creating a pull request with this change, if that's easiest.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.