DEV Community

Rakesh Gombi
Rakesh Gombi

Posted on

Build Dynamic Mock APIs Effortlessly with AutoAPI

Build Dynamic APIs Effortlessly with AutoAPI πŸš€

Introduction

Are you tired of manually creating RESTful APIs for every new project? Do you wish there was a way to dynamically generate APIs based on your file structure? Look no further! AutoAPI is here to revolutionize the way you build and manage APIs.

AutoAPI is a FastAPI-based project that dynamically generates RESTful Mock APIs based on the directory and file structure of a specified root directory. Whether you're prototyping, testing, or building a full-fledged application, AutoAPI simplifies the process of managing resources and records.


Why Choose AutoAPI for Dynamic API Generation?

In the fast-paced world of software development, time is of the essence. Developers often spend countless hours defining routes, managing resources, and handling CRUD operations. AutoAPI eliminates this overhead by:

  • Automating API Route Generation: No need to manually define routes for each resource.
  • Simplifying Resource Management: Easily create, list, and delete resources.
  • Streamlining Record Management: Handle JSON-based records with minimal effort.
  • Enhancing Productivity: Focus on building features instead of boilerplate code.

Key Features of AutoAPI

1. Dynamic Route Generation

AutoAPI automatically creates API routes based on the directory structure under the root directory. Each directory represents a resource, and each JSON file within a directory represents a record.

2. Resource Management

  • Create Resources: Add new directories for resources.
  • List Resources: View all available resources.
  • Delete Resources: Remove unwanted resources.

3. Record Management

  • CRUD Operations: Create, read, update, and delete JSON-based records.
  • Pagination: Efficiently list records with offset and limit parameters.

4. Real-Time Updates

AutoAPI monitors changes in the root directory and dynamically updates the API routes, ensuring your API is always in sync with your file structure.

5. Easy Configuration

Set up your root directory using a simple .env file. No complex configurations required.


How AutoAPI Works

Directory Structure

AutoAPI generates routes based on the following structure:

ROOT_DIR/
β”œβ”€β”€ users/
β”‚   β”œβ”€β”€ 1.json
β”‚   β”œβ”€β”€ 2.json
β”œβ”€β”€ posts/
β”‚   β”œβ”€β”€ 1.json
Enter fullscreen mode Exit fullscreen mode
  • Resource Routes: /users, /posts
  • Record Routes: /users/{id}, /posts/{id}

Example Endpoints

  • List Resources: GET /list-resources
  • Create Record: POST /users
  • Update Record: PUT /users/1
  • Delete Record: DELETE /users/1

Getting Started with AutoAPI

Prerequisites

  • Python 3.12 or higher
  • pip (Python package manager)

Installation

  1. Clone the repository:

       git clone https://github.com/Rakeshgombi/AutoAPI.git
       cd AutoAPI
    
  2. Set up a virtual environment:

       python -m venv .venv
       source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install dependencies:

       pip install -r requirements.txt
    
  4. Configure the root directory:

    • Create a .env file and define the root directory:

       ROOT_DIR=./data
      
  5. Run the application:

       uvicorn main:app --reload
    
  6. Access the API documentation:

    • Navigate to http://127.0.0.1:8000/docs for the Swagger UI.

Running with Docker

Prerequisites

  • Docker installed on your system.

Steps

  1. Clone the repository:

       git clone https://github.com/Rakeshgombi/AutoAPI.git
       cd AutoAPI
    
  2. Build the Docker image:

       docker build -t autoapi .
    
  3. Run the Docker container:

       docker run -p 8000:8000 autoapi
    
  4. Access the API:

    • Open your browser and navigate to http://127.0.0.1:8000/docs for the Swagger UI.

Use Cases for AutoAPI

1. Prototyping

Quickly set up APIs for testing and prototyping without writing a single line of backend code.

2. Mock APIs

Generate mock APIs for frontend development or integration testing.

3. Data Management

Easily manage JSON-based data for small-scale applications or experiments.


Contributing to AutoAPI

We welcome contributions from the community! If you have ideas for new features or improvements, feel free to fork the repository, create a new branch, and submit a pull request.


Call to Action

Ready to simplify your API development process? Check out the AutoAPI repository and start building dynamic APIs today!

πŸ‘‰ Explore the Repository


Acknowledgments

Special thanks to the creators of FastAPI, Pydantic, and Uvicorn for providing the tools that make AutoAPI possible.


Top comments (0)