API Maker

The backend engine for the AI era

Chapters

What you will learn

  • One envelope for every API
  • A bad request refused, and messy input cleaned, without code
  • Standard errors thrown by the code, the same in every language
  • Listed errors, translated
  • Generated Interfaces: typed rows, wrong names refused
  • A real bug: the stack, its line, and the fix live on every server
  • Why AI-written code stays on the standard
In the docsError messages
Transcript1347 words · click a time to play from there

Intro

Custom APIs, part two. In this video, your code follows one standard, no matter who writes it. And we find a bug, fix it, and make it live again in seconds.

Every service its own rules

In many teams, each service makes its own error format, and every app must learn each one. Checks on the input are forgotten, or copied by hand into each endpoint. Field names are guessed, and a typo is found only in production. A one line fix waits for a build and a deploy. And an AI assistant copies whatever it sees. API Maker gives every API one answer format. It checks each request before your code runs.

It gives a type to every table. And a save is live for the very next call. There are five parts. The standard answer. Checks with no code. The errors you throw. Typed tables in the editor. And a real bug, fixed in seconds.

The standard answer

Every API of API Maker answers in the same shape. This is true for the APIs of your tables, the system APIs, and your custom APIs. When it works, success is true. statusCode is the HTTP status. And data holds what your code returned. When it fails, errors is a list. Each error has a code and a message. For bad data, it also names the field and the rule that failed.

The code of the first error is the HTTP status. So a client writes its error handling only once, for every API. Here is the API of this video. Before checkout, the mobile app of Calm Home asks for the price of a cart. Nisha opens Custom API, and clicks Add New. Basic Info holds the settings, in TypeScript: the name, Cart Quote, its path, its method, and token access.

Then come two standards: a schema for the request body, and the list of error messages this API may throw. The Code tab holds one function, main. It reads the products of the cart from MongoDB, and the coupon from MariaDB, with g.sys.db calls. If a coupon is unknown or too old, it throws a standard error: a code and a message. Save it, and the API is live. It is in the checkout folder, with a Body chip.

This chip means that a schema checks its body.

Validation without code

That body schema uses the same language as your table schemas. Every field has a type. Checks refuse bad values: required, email, minimum, and maximum. Changes clean the values first: trim, lower case, and upper case. And an array of objects is written like the variants of a MongoDB product. So you learn one language, for tables and for APIs. Now Test API opens API Testing on Cart Quote. Nisha sends a bad cart.

The email has no domain, the quantity is zero, and one key is spelled wrong. API Maker answers 400, with every problem at once. A key the schema does not know. An email that is not valid. And the minimum of items.quantity. Not one line of the code ran. Messy input is cleaned before your code sees it. The email has spaces and capital letters, the SKU is in small letters, and the coupon has spaces.

The code got a clean email, the SKU in capital letters, and the coupon WELCOME5. The subtotal is 121.80. Five percent is taken off, shipping is 9.90, and the total is 125.61. There is no parsing, no trimming, and no check in main.

The errors you throw

Business rules live in your code, and so do their errors. The coupon SPRING15 ended in March. The code throws an error, and API Maker writes the answer: 404, in the same shape, with the message from the error list. Any other value that is thrown becomes a 500, with its stack. So even an error that nobody planned keeps the same shape. This standard is the same in every language that API Maker runs.

TypeScript throws an array. Python raises g.Errors. PHP, C sharp, Java, and Kotlin throw AmErrors. Go and Rust return a failure. Here, a Python version of the coupon check answers 404, in the same shape. And when Python itself fails, the stack shows main.py, the line number, and the line of code. You can also translate the messages of the error list. They show up in i18N Management, in the sample of every new translation.

When a caller sends the header x-am-internationalization, with fr, it gets the French message, from the same code.

Typed tables

API Maker writes your types for you. Generated Interfaces shows the file db-interfaces.ts. There is an interface for every table with a schema. Here are the products of MongoDB, with their specs and variants inside. A map links each instance, database, and table to its interface. That is twenty three tables, in six databases. The file types.ts describes g itself, with every call and its options. You can download both in one click.

The same files are also in your Git repository. In the editor, these types work while you type. The call names mongodb, catalog, and products, so the rows have a type. After product dot, the columns of the table show up, with their types. Write price with a typo, and the editor underlines it before anything runs. It says: property prise does not exist on IProducts. Did you mean price?

An AI assistant gets the same signal, from the same types. Names written as text are checked too, when the code runs. Say the code asks MongoDB for SKU, in capital letters. A database would quietly find nothing. But API Maker refuses the query: there is no property SKU in the schema of products. You see the wrong name, instead of an empty result.

A real bug

Now a real bug. The app still has a cart with CH-LGT-009. This lamp is not sold any more. The answer is 500: cannot read properties of undefined, reading price. The stack shows only your code: MainSandbox.ts, line 14. And the Code tab underlines that line in red. What the code printed is one click away. Console Logs View shows the line of this call: one of two products found.

So one SKU is missing, and the code never checked it. The fix is one line. If there is no product, throw a standard 404 that names the SKU. Command E sends the request with the code on the screen, before you save it. The answer is 404: product CH-LGT-009 is not sold any more. Meanwhile, callers still get the saved code. Command S saves it. The changes are saved.

Saving is deploying. The very next call from outside gets the fixed answer. The API lives in the database of API Maker. When you save, every server of the cluster is told, through Redis, to drop its old copy. So each server runs the new code on its next request. No build, no image, and no restart.

Why AI-written code stays on the standard

This is why code written by an AI assistant stays on the standard. The request schema runs before any code, so a missing check cannot let bad input in. Typed tables show a wrong name while the code is written. There is one way to fail, so every error reaches the client in one shape. And a fix is tried on real data, then saved, in seconds. The assistant and the developer follow the same rules.

Best practices

A few habits keep it this way. Give every body and every query a schema. Throw a code and a message, with the right status. List the messages you throw in errorList, so each one can be translated. Write the instance, the database, and the table as text in each call, so rows keep their type. And to check a payload without calling the API, use is valid data for custom API.

Recap

To sum up. One answer shape, for every API. Schemas that check and clean each request. Standard errors, in every language. Typed tables, from Generated Interfaces. And a fix, live in seconds. Next, the hidden gems of custom APIs, from file uploads to caching. API Maker. Build faster, spend smarter, deliver better.