DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Model-Driven Development and Testing
  • AI-Driven Development: Maximizing Efficiency With GitHub Copilot and Seamless Chat Collaboration in Visual Studio IDE
  • Upgrading a Database Project to Python 3.12
  • API Appliance for Extreme Agility and Simplicity

Trending

  • Artificial Intelligence, Real Consequences: Balancing Good vs Evil AI [Infographic]
  • Immutable Secrets Management: A Zero-Trust Approach to Sensitive Data in Containers
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  • How to Practice TDD With Kotlin
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Instant APIs With Copilot and API Logic Server

Instant APIs With Copilot and API Logic Server

Describe a database to Copilot, and create a running API and Admin App in moments. Or, use an existing database. Customize in your IDE with Rules and Python.

By 
Val Huber user avatar
Val Huber
DZone Core CORE ·
Apr. 11, 24 · Tutorial
Likes (11)
Comment
Save
Tweet
Share
3.4K Views

Join the DZone community and get the full member experience.

Join For Free

Creating an API and an admin app using a framework takes too long, and is far too complex. AI and automation can create systems in minutes rather than weeks or months, dramatically simpler, and fully customizable with tools and approaches you already know.

In this tutorial, we'll show how to create a complete system using VS Code, Copilot, and API Logic Server (open source). We'll then add business logic with rules, and use Python to add a custom endpoint and Kafka integration.  Links are provided so you can execute these steps on your own.

Overview

As shown below, you can submit a Natural Language description of a database to Copilot. This creates a Python data model (SQLAlchemy classes).  

You then use API Logic Server CLI to create an executable project from the model. Alternatively, you can create a project by identifying an existing database.

The project is executable, providing an API and an admin app, enabling agile collaboration and unblocking custom app dev.

Overview

Figure 1: Overview

Setup

To begin, install Python and VSCode. Optionally, install Copilot: it's moderately priced and you can execute this tutorial without it. But, it provides the Natural Language services shown here - it's quite a lot of fun to explore, so you might just want to splurge and acquire it.

Then, install the API Logic Server and start it:

Shell
 
python3 -m venv venv                 # windows: python -m venv venv 
source venv/bin/activate             # windows: venv\Scripts\activate 
python -m pip install ApiLogicServer

ApiLogicServer start


This will launch the API Logic Server in VSCode. We've moved the Copilot chat pane to the right.

API Logic Manager in your IDEFigure 2: API Logic Manager in your IDE

1. Create Your Model With Copilot

The README page includes the Natural Language Text to supply to Copilot; paste it, and press enter. It's shown in the diagram below in dark gray ("Use SQLAlchemy to...").

Copilot creates the SQLAlchemy model code.

Paste the generated code into a new model file called sample_ai.py (step 2 in Figure 3 below):

Creating a project with Copilot and API Logic Server

Figure 3: Creating a project with Copilot and API Logic Server

2. Create a Project With API Logic Server

Create your project (step 3 in Figure 3 above) by entering the following into the bottom terminal pane (als is a synonym for ApiLogicServer):

Shell
 
als create --project-name=sample_ai --from-model=sample_ai.py --db-url=sqlite


API Logic Server uses SQLAlchemy (a popular Python ORM) to create a database from the Copilot model and then creates a fully formed project by reading the database schema. The project includes your data model classes, your API, and your admin app, fully configured for execution.

Here the target database is SQLite; the same scenario will work for other databases as well, but you will need to replace "sqlite" with a full URI of your database.

Create Project From Existing Database

Alternatively, if you don't have Copilot, you can use an existing database, and create your project using the pre-installed SQLite database (1b in Figure 1):

Shell
 
als create --project-name=sample_ai --db-url=sqlite:///sample_ai.sqlite


3. Microservice Automation: Executable Project

In either case, API Logic Server creates a fully formed project, ready to run, and launches it in another instance of VSCode:

Created Project (new VSCode instance)

Figure 4: Created Project (new VSCode instance)

Press F5 to start the server; launch the created admin app in your browser to explore your data and the API:

  • The admin app, based on React Admin, provides data query/update services, with multi-table support for automatic joins and page navigations. This can kick-start agile business user collaboration, and provide back-office data functions.
  • A JSON API, provides retrieval/update services, including support to choose columns and related data. This unblocks custom app dev, which is often compressed into the end of the project while waiting on custom API development.

Compare automation to framework-based development: With a framework, you are ready to code. With automation, you are ready to run.

Microservice Automation - created admin app and API

Figure 5: Microservice Automation - created admin app and API

So, we have working software: an admin app, for business user collaboration; an API, to unblock custom app dev.

It was fast - only took a few moments - and simple - did not require months to learn a framework.

4a. Customize With Rules: Logic Automation

Well, "fast and simple" is great, but it's little more than a stupid pet trick without logic and security. That's often nearly half the work of a transactional database application.

API Logic Server contains a rule engine. You can declare rules in Python, using IDE code completion services.  

It also provides value: spreadsheet-like rules reduce logic code (half the app) by 40X.

But, we can have much more fun.  As shown below, we can ask Copilot to create these rules for us, and paste them into a pre-created file:

Creating Rules with Copilot

Figure 6: Creating Rules with Copilot

These 5 lines of code look just like the requirements, so the level of abstraction is remarkably high. These 5 declarative rules would have required 200 lines of traditional procedural code.

And they are executable. They listen for SQLAlchemy ORM events, and fire in response to the actual changes in the transaction. Rules (and their overhead) are pruned if their referenced data is unchanged.

Rules are debuggable. Standard logging depicts each rule firing, including the state of the row. And, you can use your debugger. 

Similar declarative rules are provided for row-level security, based on a user's roles. Authorization information can be obtained from a SQL database, or corporate stores such as LDAP or Active Directory.

4b. Customize With Python

Automation is great, but let's face it: you can never automate everything. It's mandatory to have a customization capability that is standards-based — using our favorite IDE, standard languages like Python, and standard frameworks like SQLAlchemy and Flask.

Let's examine 2 typical customizations: a custom endpoint, and Kafka integration.

Custom API Endpoint

Imagine accepting orders in a designated format from a B2B partner. The custom endpoint below performs the transformation using order_b2b_def (a declarative mapping definition, not shown), and saves it. This automatically activates the business rules above to check credit.

Customization - Adding a Custom Endpoint

Figure 7: Customization - Adding a Custom Endpoint

Custom Logic for Kafka Integration

Let's further imagine that accepted orders must be further transformed, and sent to shipping via a Kafka message. The screenshot below illustrates that, in addition to rules, you can provide Python code for business logic. Here you have all the power of Python libraries: Flask, SQLAlchemy, Kafka, etc.

Customization - Kafka Integration

Figure 8: Customization - Kafka Integration

5. Deploy

Value is not realized until the system is deployed, whether for final production, or early collaboration with stakeholders. API Logic Server creates scripts to containerize your project, and deploy to Azure with Docker Compose:

API Logic Server creates scripts to containerize your project, and deploy to Azure with Docker Compose

Summary

The screenshots above illustrate remarkable agility. This system might have taken weeks or months using conventional frameworks.

API Appliance toaster image

But it's more than agility. The level of abstraction here is very high, bringing a level of simplicity that empowers you to create microservices - even if you are new to Python or frameworks such as Flask and SQLAlchemy.

Instead of a complex framework, it's more like an appliance — just plug into your idea or existing database, and you have an executable, customizable project.

There are 4 key elements that deliver this speed and simplicity:

  1. Natural Language Processing: Even savvy SQL programmers welcome syntax help. It's a dream come true to start from Natural Language, as provided by Copilot.
  2. Microservice automation: Instead of slow and complex framework coding, just plug into your database for an instant API and Admin App.
  3. Logic automation with declarative rules: Instead of tedious code that describes how logic operates, rules express what you want to accomplish, and reduce the backend half of your application by 40x.
  4. Extensibility: Finish the remaining elements with your IDE, Python, and standard packages such as Flask and SQLAlchemy.

Automation empowers more people, to do more.

API Integrated development environment Visual Studio Code Framework Python (language) AI

Opinions expressed by DZone contributors are their own.

Related

  • Model-Driven Development and Testing
  • AI-Driven Development: Maximizing Efficiency With GitHub Copilot and Seamless Chat Collaboration in Visual Studio IDE
  • Upgrading a Database Project to Python 3.12
  • API Appliance for Extreme Agility and Simplicity

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!