Frappe is an incredible Python-based, metadata-driven, low-code framework that simplifies web application development. It’s designed to help developers focus on creating the core architecture of their apps while Frappe handles a lot of the heavy lifting. With its intuitive user interface and powerful hook system, Frappe lets you extend and customize internal processes to fit your unique requirements.needs.
One of the standout features of Frappe is its ability to seamlessly integrate custom API endpoints. These endpoints can be accessed using Frappe’s native dotted paths, making integration easy and efficient. For example, a typical custom API route in Frappe looks like this:
/api/method/yourapp.module.method
This dotted-path approach works great, especially when you’re just starting out with an app. However, as your app scales and you introduce more APIs, things can get messy. Since the method name is embedded in the API path, you end up with long, complex paths that are harder to read and maintain. Managing a growing number of APIs can quickly become cumbersome, and naming conventions can easily get out of hand.
But what if there was a way to name your APIs freely, without worrying about long method names and confusing paths? Well, that’s exactly where RouteX comes in. RouteX is a Frappe app that lets you define your API routes however you want. You can group them logically, giving you the flexibility to implement versioning for your APIs, and best of all, it keeps the paths clean and easy to understand.
Traditionally you would use frappe’s whitelist
decorator to create an API endpoint, with RouteX you will do it the similar way:
from routex import routex_whitelist
import frappe
@routex_whitelist("get-users")
def get_users():
return frappe.get_list("User",fields=["*"])
# /api/app-name/get-user
Under the hood, routex_whitelist
automatically registers your method with Frappe’s native frappe.whitelist
decorator, which means your API method becomes accessible both via the custom RouteX-defined path and the traditional dotted path if needed.
Not only can you define custom route names, but you can also logically group your APIs by behavior, module, or version to keep your API structure clean and maintainable.
from routex import routex_whitelist
import frappe
@routex_whitelist("get-active-users",group="users")
def get_active_users():
return frappe.get_list("User",fields=["*"],filters={"enabled":True})
# /api/app-name/users/get-active-user
Since your methods will be automatically registered with the frappe.whitelist
, all the routing will be handled by core, also one can pass all the parameter frappe.whitelist accepts, RouteX only handles the routing. So if you have app name called next_crm
, it will become the base of your routes to make it unique, hence your routes will become something like /api/next-crm/get-active-users
.
RouteX makes API management in Frappe clean, flexible, and easy to scale. If you’re building custom apps, give it a try and ✨ if you like it.
Be First to Comment