GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Pythonium
  • Code checker
  • Fixer
  • JS
  • Formatter
  • Regex
  • Obfuscator
  • Mock API
  • Data
  • Pickle
  • Wheel
  • Blog
  • Cheatsheet
  • Sandbox

This view

  • Original page
  • New address

GeezerVison is showing pythonium.net — Mock API - Pythonium

A free and open-source fake API designed for testing and prototyping, with Python for added flexibility.

Custom API & Rule Engine
Instantly generate a custom API from a JSON object and customize its behavior with a Python rule engine. Define rules to handle errors, modify HTTP responses, headers, and bodies using Python scripts—all for free and open source. Access the source code to set up your own local instance.

How to Create a Custom API?
MockAPY, available on GitHub, lets you create a local mock API with custom rules. Alternatively, you can generate an API online using the editors below, but without custom rules. The API will be immediately accessible but is deleted once a day. If needed, you can recreate it on this page. For frequent usage, consider setting up a local API to avoid limitations.

Resources



Your endpoint was set to



Your endpoint API is now available here:

Access to your resources:

Note: Once a day, the APIs are deleted. You can return to this page to recreate your API.

Documentation

Routes

GET/productsReturns all products
GET/products/2Returns the product with ID 2
POST/productsCreate a new product
GET/products/2Returns the product with ID 2
PUT/products/2Update the product with ID 2
PATCH/products/2Update partially the product with ID 2
DELETE/products/2Delete the product with ID 2

Configuration of the resources

All resources must be contained within a single JSON object, where each attribute represents a resource holding an array of elements.

In this example, two resources have been created: "products" and "users", each containing two elements.

{
  "products": [
    {
      "id": "1", "name": "T-shirt", "price": 19.99
    },
    {
      "id": "2", "name": "Jeans", "price": 49.99
    }
  ],
  "users": [
    {
      "id": "1", "username": "johndoe", "email": "[email protected]"
    },
    {
      "id": "2", "username": "janedoe", "email": "[email protected]"
    }
  ]
}

Configuration of the rules

Custom rules are defined using Python code, allowing you to set conditions based on the request (e.g., HTTP method, headers, and payload) and control the response (including HTTP status code and payload). This enables you to customize the API's behavior for specific testing and development needs.

Rules are executed before the API processes data (reading, writing, or deleting).

The HTTP status and payload specified in the rules override those defined by the API.

Here is an example of a rule that returns an HTTP status 401 when accessing the resource /products/23:

import request
import response
import json

def handle_request():
    if request.pathname() == "/products/23":
        response.status(401)
        response.exit()

The exit method indicates whether to halt after applying the rule or to continue with the API execution.

Input

The input object is used to represent the different criteria that can be tested in the request.

AttributeDescription
headersThe headers (Object: each header is an attribute)
methodThe HTTP method (‘GET’, ‘POST’, ‘PUT’, ‘PATCH’, ‘DELETE’)
pathThe pathname of the URL (e.g., /users/23).
payloadThe payload (object or string)

Output

The output object is used to update the response if the rule match.

AttributeDescription
statusSets the HTTP status (e.g., 200, 404, etc.)
responseSets the response payload
headersSets the headers (Object: each header is an attribute)

Why use a mock API when developing with Python?

Using a Mock API is incredibly useful when developing web applications with Python, especially with Django, Flask, and FastAPI. It allows developers to simulate API responses, which is helpful for testing applications even when the actual API is unavailable or still under development. It also makes it much easier to handle error scenarios such as timeouts, HTTP 500 errors, or invalid responses. Hopefully, this simple yet powerful Mock REST API tool will be useful to you!




Popular posts
  • The impact of technology on business scalability

    Businesses must be both fast and adaptable—two essential levers for growth. Technologies like AI, automation, and cloud computing have become indispensable. Failing to adapt means risking serious setbacks compared to the competition. I once worked for a software company that didn’t believe in the cloud—this cost them dearly… We’ll explore how these tools are transforming […]

  • Artificial Intelligence: The next technological revolution after the Internet?

    The creation of the Internet at the end of the last century revolutionized our lives (for better or worse, depending on one's perspective…). But it didn't happen overnight; it took decades to profoundly transform our societies after its invention. Artificial intelligence seems to be following a similar trajectory. Often overestimated in the short term—just look […]

  • Essential Python libraries for Data Science

    When you're a developer looking to dive into data science, you immediately think of Python ^^ (Okay, maybe I'm a bit biased haha). It’s fair to say that Python remains the undisputed star of the field, with a massive and rich ecosystem!In this article, we’ll take a tour of the must-know Python libraries, organized by […]

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.