Instant App Backends with API and Logic Automation
I saw career advice recommending against front end development --?"you're dependent on APIs - they're late, so front end dev is always under pressure." ?Sad, but a story I hear often. ?The problem is that framework-based API development is slow and complex.
I also hear snide remarks that "if you don't like the answer from UI #1, try UI #2". ?It's because the?logic is often not shared in the server, but replicated on UI controllers.
Slow framework-based development and unshared logic are really backend problems, affecting dev teams and business agility. ?Now, there's a solution.
API Automation enables you to create backends instantly - ready for client app dev. ?Logic Automation addresses the logic under the API with rules that are 40x more concise than code. ?API Logic Server, an open source Python project, makes this possible. ?Here's how.
API Automation: 1 Command to Create Database API
API Automation means you create a running API with 1 command:
? ApiLogicServer create --project_name=ApiLogicProject \
? ? ? ? ? ? ? ? ? ? ? ? --db_url=postgresql://postgres:p@localhost/nw
API Logic Server ?reads your schema, and creates an executable project that you can customize in your IDE.
JSON:API - client app dev ready
With zero framework-based coding, you now have a running API (and an Admin Web App not shown here):
The API follows the JSON:API standard. ?Analogous to GraphQL, JSON:APIs are self-serve: front end developers request the fields and related data they want, as shown above using automatically created Swagger. ?Swagger provides the Request URL you can paste into your client code.
JSON:API frees the client app developers from depending on server custom API development.
Contrast this to traditional API development, where:?
JSON:API creation is automated with 1 command; self-serve enables app dev, instantly.
This is also a great way to get instant integrations - click here.
Full Access to Underlying Frameworks: Custom Endpoints
The create command creates a full project you can open in your IDE, and customize with all the power of Python and frameworks such as Flask and SQLAlchemy. ?This enables you to build custom APIs that bundle multi-row updates into 1 transaction. ?
Here's the code for an endpoint to post an Order and OrderDetails:
The entire code is shown in the upper pane. It's only around 10 lines, because:
Implement custom endpoints, using Python and standard frameworks.
Logic Automation: Rules are 40X More Concise
While our API is executable, it's not deployable until it enforces logic and security. ?Such backend logic is a significant aspect of systems, often accounting for nearly half the effort. ?It's the iceberg under the surface.
Frameworks have no provisions for logic. ?They simply run code that you design, write and debug.
Logic Automation means you declare rules using your IDE, adding Python where required. ?With keyword arguments, typed parameters and IDE code completion, Python becomes a Logic DSL (Domain Specific Language). ?Let's explore declaring rules for security and logic.
Declaring Security Logic
Here is a security declaration that limits customers to see only their own row:
领英推荐
Grant(? on_entity = models.Customer,
? ? ? ? to_role = Roles.customer,
? ? ? ? filter = lambda : models.Customer.Id == Security.current_user().id,
? ? ? ? filter_debug = "Id == Security.current_user().id") ? ? # customers can only see their own account
Grants are typically role-based as shown above, but you can also do global grants that apply across roles, here for multi-tenant support:
GlobalFilter(? ?global_filter_attribute_name = "Client_id",? # try customers & categories for u1 vs u2
? ? ? ? ? ? ? ? roles_not_filtered = ["sa"],
? ? ? ? ? ? ? ? filter = '{entity_class}.Client_id == Security.current_user().client_id')
Security is factored out of front end code, shared in the server.
Declaring Transaction Logic
Declarative rules are particularly well-suited for update logic. ?For example, imagine the following cocktail napkin spec to check credit:
The rule-based implementation below illustrates that rules look like an executable design:
Rules operate by plugging in to SQLAlchemy (ORM) events. ?They operate like a spreadsheet?to automate multi-table transactions:
Spreadsheet-like rules are 40X more concise. Declare and Debug in your IDE, Extend With Python.
Events - e.g., send email, Kafka messages
Rules automate in excess of 97% of your database transactional logic. ?But not all.
To complement rule-based agility, the system also supports events where you can implement standard Python code. ?You have all the power of Python libraries, e.g., for sending Kafka messages or email. ?The example above illustrates sending a Kafka message when an Order is posted.
Logic Partitioning - reuse, simplify client app dev
Logic execution is on the server. ?That means it can be shared:
So, for example, our credit check logic is shared between client apps and the B2B service, automatically.
This addresses a common - and serious - architectural error, where "fat clients" implement business logic. ?This is hard to share between client apps, and impossible to share with services.
Logic partitioning also reduces - significantly - the code required in client apps.?
Parallel Client / Server Development
Logic automation also enables client and server development to proceed in parallel. ?As server developers implement logic, the same APIs simply provide more functionality, within the same interface. ?From the client perspective, the API is available immediately, and remains unchanged. ?
This is in stark contrast to traditional framework based development, where client app dev is serialized, after lengthy API implementation.
Summary: Remarkable Business Agility
So there you have it - remarkable business agility to unblock and accelerate front end app dev. ?This is enabled by:
Compared to framework-based development, you might say that API and Logic Automation are a horse of an entirely different feather.
That said, frameworks are great for customizing what is not automated. ?So: automation for business agility, standards-based customization for flexibility.
API Logic Server is free and open source. ?You can install it and explore running code for these examples - click here.
AIMicroservice Consulting
9 个月API Automation, a new dev category
Very nicely presented Val. I am totally onboard! However, I need a cluster of these APIs across multiple databases and schemas representing various parts of my business. How can I pull them together with Api Logic Server?
Senior Managing Director
9 个月Val Huber Very interesting. Thank you for sharing