Athena
Home
Environments
Environments
  • Development Server
  • Production
Home
Environments
Environments
  • Development Server
  • Production
  1. Developers
  • Getting Started
    • Start Guide
  • Installation & Setup
    • Windows
  • Architecture
  • Guide
    • Bundles
      • Backend
    • Permissions
      • Frontend
    • Developers
      • Commit Lint
      • RESTful API
    • Workflows
      • Workflow Variables
  • API Reference
    • Authentication
      • Sign In
      • Logout
    • User
      • Get Authenticated User using Multiplai App Access Token
      • Get Authenticated User using Basic Token
    • Workspace
      • Get Workspaces Metrics
      • Get Workspaces
      • Update a Workspace
      • Retrieve a workspace
      • Delete a Workspace
    • Provider
      • Get Providers
      • Retrieve a Provider
      • Update a Provider
      • Create a Provider
      • Delete a Provider
    • Account
      • Get Accounts
      • Update an Account
      • Create an Account
      • Delete an Account
      • Retrieve an Account
    • Agent
      • Get Agents
      • Update an Agent
      • Create an Agent
      • Delete an Agent
      • Retrieve an Agent
      • Run an Agent
      • Train an Agent
      • Generate an Agent
      • Share Agent
      • Get Agent Leaderboard
    • Workflow
      • Get Workflows
      • Create a Workflow
      • Retrieve a Workflow
      • Update a Workflow
      • Delete a Workflow
      • Trigger a webhook
      • Share Workflow
      • Generate Workflow
    • Workflow Execution
      • Get Workflow Executions
      • Get Workflow Execution Counts
      • Retrieve a Workflow Execution
      • Delete a Workflow Execution
    • Prompt
      • Get Prompts
      • Create a Prompt
      • Retrieve a Prompt
      • Update a Prompt
      • Delete a Prompt
      • Run a prompt
    • Memory
      • Get Memories
      • Retrieve a Memory
      • Update a Memory
      • Delete a Memory
    • Thread
      • Get Threads
      • Retrieve a Thread
      • Update a Thread
      • Delete a Thread
      • Create a Thread
      • Run a Thread
      • Generate Thread Name
    • Message
      • Get Messages
      • Retrieve a Message
      • Update a Message
      • Delete a Message
      • Create a Message
    • Large Language Model
      • Get Large Language Models
      • Retrieve a Large Language Model
    • Command Room Task
      • Store Command Room Task
      • Remove Command Room Task
    • Metrics
      • Get Agents Metrics
      • Get Workflows Metrics
      • Get Threads Metrics
      • Get Messages Metrics
      • Get Workflow Executions Metrics
  • Schemas
    • Resources
      • User
      • Workspace
      • Provider
      • Account
      • Agent
      • Workflow
      • Share
      • WorkflowExecution
      • WorkflowExecutionData
      • Prompt
      • Memory
      • Thread
      • Attachment
      • Media
      • Tool
      • Message
      • LargeLanguageModel
      • AgentLeaderboard
    • Utils
      • Pagination
        • PaginationMeta
        • PaginationLinks
      • Provider
        • AuthenticationConfig
      • Profile
        • ProfilePhotoConfig
      • Workflow
        • WorkflowExecutionDataWorkflowData
        • Node
        • Edge
  1. Developers

RESTful API

This guide will walk you through the steps of creating a RESTful API in Laravel, from generating the necessary components to applying the Repository Pattern for data access abstraction.

Prerequisites#

Laravel installed on your development machine.
Basic understanding of Laravel's MVC architecture.
Familiarity with RESTful principles.

Step 1: Create a Model and Migration#

Start by creating a model for your resource. For example, if you're creating a task management system, you'll need a Task model.
This command creates a model file in app/Models/Task.php and a migration file in database/migrations/ for the tasks table.

Step 2: Define the Migration#

Open the generated migration file and define the structure of your tasks table.
Run the migration to create the table:
Step 3: Create a Resource Controller
Generate a controller for your resource with CRUD operations predefined by Laravel.
This command creates a controller under app/Http/Controllers/Resource/TaskController.php with methods for index, show, store, update, and destroy.

Step 4: Create a Factory#

This will allow use to test your model later on or create database seeds.
Here's how it would look like:

Step 5: Create Repository#

Create a repository by extending your repository class to app/Repositories/Repository.php.
Override the necessary methods as you may need, such as find, filter, create, paginate, update, and delete.

Why create a repository?#

Repository is a layer between your controller and your model. This is where you put custom business logic needed between them, such as adding additional database column information, or request input transformation requirements.
It should be designed to be reusable in cases you need to create separate controller for other needs, and void having to write the same code. Therefore this is to eradicate code redundancy within the project.

Step 6: Create Resource#

Create a JsonResource class for Task by simply executing this command:
Then customize as needed.

Step 7: Create Request Class#

Create the needed request classes to be used on your controller. You should place them on a directory related to the Model it is intended to, for example: app/Http/Requests/Task/RetrieveTasksRequest.php
You have to create request class for each request types:
app/Http/Requests/Task/IndexRequest.php
app/Http/Requests/Task/ShowRequest.php
app/Http/Requests/Task/StoreRequest.php
app/Http/Requests/Task/UpdateRequest.php
app/Http/Requests/Task/DestroyRequest.php

Why do need a request class?#

This is to control the information that goes through the API endpoint and avoid SQL injections, brute force or any harmful data that could reach to your business logic. It has to be created individually for us to apply authorization logic on each type of request such as Role Based Access and Control.

Step 7: Update the Controller#

We will now use the repository to the controller:
As you can see on the example, we are using the repository to request or query tasks. The controller doesn't have to know how to query it as it should only serve as the handler whenever there's an HTTP Request.
Then we used the TaskResource as return type, this will ensure we return JSON and have the controller what data should be return to the client.

Step 8: Define Routes#

We can use the Route::apiResource method from laravel to automatically register all request types:
Edit the file routes/api.php and add the following code:

Step 9: Writing Test Scripts#

Using Pest, you must write API request tests within tests/Feature/Resource, on this case we will create tests/Feature/Resource/TaskTest.php

Run your test#

To make sure your endpoint runs correctly, you can run this very specific test by following this command:
To run all tests and ensuring nothing breaks within the application:
Modified at 2026-02-26 23:41:35
Previous
Commit Lint
Next
Workflow Variables
Built with