Page cover

Quickstart

What is AI Declare?

AI Declare is an AI agent for REST API code generation. The way you configure the agent is by using a DSL (Domain Specific Language). The DSL is embedded in the Scala programming language, and it allows to the programmers to create complex secured REST APIs in just a few minutes in different languages / frameworks.

Prerrequisites

  • Basic programming skills are a prerequisite..

  • IntelliJ IDEA (Community or Ultimate) + Scala plugin

    • Install IntelliJ IDEA.

    • In Settings → Plugins, search Scala and install it.

    • (Recommended) JDK 21+, Scala 3.3+, sbt 1.10+.

  • ChatGPT API token (OpenAI API key)

  • Register as a user here

Your first AI Declare project

1) Setup environment

Register as a user here

Setup your AI Declare credentials

2) Setup a Scala project

  1. Open IntelliJ IDEA

  2. New ProjectScalasbt.

  3. Choose your JDK, set Scala 3.x (any recent 3.x).

  4. Name the project (e.g., aideclare-sample) → Create.

This generates:

  • build.sbt

  • project/build.properties

  • project/ directory for sbt metadata

  1. Add the following code to build.sbt

  2. Sync the project

3) Implementation

Data model definition

First, define your data model. Create one Scala case class for each table in your database. Mark primary keys with @id and foreign keys with @fk, and have every case class derives EntityMetadata.

If a case class represents an application user, also derive UserInfo. In that case, annotate the username and password fields with @username and @password, respectively.

APIs definition

Next, define your REST APIs. You can expose four kinds of endpoints:

  • Public: open to everyone; no authentication required.

  • Authenticated: access restricted to specific user types/roles.

  • Me: operate on the authenticated user’s own data.

  • Sub-APIs: endpoints nested under another API; they inherit the parent’s access controls.

4) Create a project in AI Declare site

On the AI-Declare site, create a new project, then select the target language and framework for code generation.

5) Run an execution

Create a main class like the following

When you run the code you will be asked to choose a project:

6) Download the code from Executions screen

That's it, the code will be generated in a few minutes and you will be able to download it from the web site.

Click in the file icon to download generated sources.

Last updated