Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

api-analytics

> 后端框架
Open source

Effortless monitoring and analytics for API frameworks.

654 stars0 likes1 views
WebsiteGitHub

About

Effortless monitoring and analytics for API frameworks.

API Analytics

An effortless API analytics solution, complete with a dashboard.

Currently compatible with:

  • Python: FastAPI, Flask, Django and Tornado
  • JavaScript: Express, NestJS, Hono, Fastify, Koa and Elysia
  • Go: Gin, Echo, Fiber and Chi
  • Rust: Actix, Axum and Rocket
  • Ruby: Rails and Sinatra
  • PHP: Laravel and Native PHP
  • C#: ASP.NET Core

Getting Started

1. Generate an API key

Head to apianalytics.dev/sign-up to generate your unique API key with a single click. This key is used to monitor your specific API and should be stored privately. It will be required when accessing your API Analytics dashboard and logged data.

2. Add middleware to your API

Add the lightweight middleware to your API. Since most data processing is handled by the API Analytics server, it has minimal impact on your API's performance.

FastAPI

bash
pip install api-analytics[fastapi]
python
import uvicorn
from fastapi import FastAPI
from api_analytics.fastapi import Analytics

app = FastAPI()
app.add_middleware(Analytics, api_key="YOUR-API-KEY")  # Add middleware

@app.get('/')
async def root():
    return {'message': 'Hello, World!'}

if __name__ == "__main__":
    uvicorn.run("app:app", reload=True)

Flask

bash
pip install api-analytics[flask]
python
from flask import Flask
from api_analytics.flask import add_middleware

app = Flask(__name__)
add_middleware(app, "YOUR-API-KEY")  # Add middleware

@app.get('/')
def root():
    return {'message': 'Hello, World!'}

if __name__ == "__main__":
    app.run()

Django

bash
pip install api-analytics[django]

Assign your API key to ANALYTICS_API_KEY in settings.py and add the Analytics middleware to the top of your middleware stack.

python
ANALYTICS_API_KEY = "YOUR-API-KEY"

MIDDLEWARE = [
    'api_analytics.django.Analytics',  # Add middleware
    ...
]

Express

bash
npm install @api-analytics/express
javascript
import express from 'express';
import { expressAnalytics } from '@api-analytics/express';

const app = express();

app.use(expressAnalytics("YOUR-API-KEY")); // Add middleware

app.get('/', (req, res) => {
    res.send({ message: 'Hello, World!' });
});

app.listen(8080, () => {
    console.log('Server listening at http://localhost:8080');
})

Hono

bash
npm install @api-analytics/hono
javascript
import { Hono } from 'hono';
import { serve } from '@hono/node-server';
import { honoAnalytics } from '@api-analytics/hono';

const app = new Hono();

app.use('*', honoAnalytics("YOUR-API-KEY"));

app.get('/', (c) => c.text('Hello, world!'));

serve(app, (info) => {
    console.log(`Server listening at http://localhost:${info.port}`);
});

Gin

bash
go get -u github.com/tom-draper/api-analytics/analytics/go/gin
go
package main

import (
    "net/http"
    "github.com/gin-gonic/gin"
    analytics "github.com/tom-draper/api-analytics/analytics/go/gin"
)

func root(c * gin.Context) {
    data := map[string]string{
        "message": "Hello, World!",
    }
    c.JSON(http.StatusOK, data)
}

func main() {
    r := gin.Default()
    
    r.Use(analytics.Analytics("YOUR-API-KEY")) // Add middleware

    r.GET("/", root)
    r.Run(":8080")
}

Fiber

bash
go get -u github.com/tom-draper/api-analytics/analytics/go/fiber
go
package main

import (
    "github.com/gofiber/fiber/v2"
    analytics "github.com/tom-draper/api-analytics/analytics/go/fiber"
)

func root(c *fiber.Ctx) error {
    data := map[string]string{
        "message": "Hello, World!",
    }
    return c.JSON(data)
}

func main() {
    app := fiber.New()

    app.Use(analytics.Analytics("YOUR-API-KEY")) // Add middleware

    app.Get("/", root)
    app.Listen(":8080")
}

Actix

bash
cargo add actix-analytics
rust
use actix_web::{get, web, App, HttpServer, Responder, Result};
use serde::Serialize;
use actix_analytics::Analytics;

#[derive(Serialize)]
struct JsonData {
    message: String,
}

#[get("/")]
async fn index() -> Result {
    let data = JsonData {
        message: "Hello, World!".to_string(),
    };
    Ok(web::Json(data))
}

#[actix_web::main]
async fn main() -> std::io::Result {
    HttpServer::new(|| {
        App::new()
            .wrap(Analytics::new("YOUR-API-KEY"))  // Add middleware
            .service(index)
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}

Axum

bash
cargo add axum-analytics
…

Rails

bash
gem install api_analytics

Add the analytics middleware to your rails application in config/application.rb.

ruby
require 'rails'
require 'api_analytics'

Bundler.require(*Rails.groups)

module RailsMiddleware
  class Application  new { message = "Hello, World!" });

app.Run();

Other Frameworks

  • Python: Tornado
  • JavaScript: Fastify, Koa, Elysia, Bun, NestJS, Oak, H3
  • Go: Echo, Chi
  • Rust: Rocket
  • PHP: PHP

3. View your analytics

Your API will now log and store incoming request data on all routes. Logged data can be viewed using two methods:

  1. Through visualizations and statistics on the dashboard
  2. Accessed directly via the data API

The same API key can be used across multiple APIs, but all requests will appear in the same dashboard. It's recommended to generate a new API key for each of your API servers.

Dashboard

Head to apianalytics.dev/dashboard and paste in your API key to access your dashboard.

Demo: apianalytics.dev/dashboard/demo

Data API

Raw logged request data can be fetched from the data API. Simply send a GET request to https://apianalytics-server.com/api/data with your API key set as X-AUTH-TOKEN in the headers.

Python
python
import requests

response = requests.get("https://apianalytics-server.com/api/data", headers={
    "X-AUTH-TOKEN": "YOUR-API-KEY"
})
print(response.json())
Node.js
javascript
fetch("https://apianalytics-server.com/api/data", {
    headers: { "X-AUTH-TOKEN": "YOUR-API-KEY" },
})
    .then((response) => {
        return response.json();
    })
    .then((data) => {
        console.log(data);
    });
cURL
bash
curl --header "X-AUTH-TOKEN: YOUR-API-KEY" https://apianalytics-server.com/api/data
Parameters

You can filter your data by providing URL parameters in your request.

  • page - the page number, with a max page size of 50,000 (defaults to 1)
  • date - the day the requests occurred on (YYYY-MM-DD)
  • dateFrom - a lower bound of a date range the requests occurred in (YYYY-MM-DD)
  • dateTo - a upper bound of a date range the requests occurred in (YYYY-MM-DD)
  • hostname - the hostname of your service
  • ipAddress - the IP address of the client
  • status - the status code of the response
  • location - a two-character location code of the client
  • userId - a custom user identifier (only relevant if a get_user_id mapper function has been set within config)

Example:

bash
curl --header "X-AUTH-TOKEN: YOUR-API-KEY" https://apianalytics-server.com/api/data?page=3&dateFrom=2022-01-01&hostname=apianalytics.dev&status=200&userId=b56cbd92-1168-4d7b-8d94-0418da207908

Client ID and Privacy

By default, API Analytics logs and stores the client IP address of all incoming requests made to your API and infers a location (country) from each IP address if possible. The IP address is used as a form of client identification in the dashboard to estimate the number of users accessing your service.

This behaviour can be controlled through a privacy level defined in the configuration of the API middleware. There are three privacy levels from 0 (default) to a maximum of 2. A privacy level of 1 will disable storage of IP addresses, and a value of 2 will also disable location inference.

Privacy Levels:

  • 0 - The client IP address is used to infer a location and then stored for user identification. (default)
  • 1 - The client IP address is used to infer a location and then discarded.
  • 2 - The client IP address is never accessed and location is never inferred.
python
from fastapi import FastAPI
from api_analytics.fastapi import Analytics, Config

config = Config(privacy_level=2)  # Disable IP storing and location inference

app = FastAPI()
app.add_middleware(Analytics, api_key="YOUR-API-KEY", config=config)  # Add middleware

With any of these privacy levels, you have the option to define a custom user ID as a function of a request by providing a mapper function in the API middleware configuration. For example, your service may require an API key held in the X-AUTH-TOKEN header field which is used to identify a user of your service. In the dashboard, this custom user ID will identify the user in conjunction with the IP address or as an alternative depending on the privacy level set.

python
from fastapi import FastAPI
from api_analytics.fastapi import Analytics, Config

config = Config(
    get_user_id=lambda request: request.headers.get('X-AUTH-TOKEN', '')
)

app = FastAPI()
app.add_middleware(Analytics, api_key="YOUR-API-KEY", config=config)  # Add middleware

Data and Security

All data is stored securely, and in compliance with The EU General Data Protection Regulation (GDPR).

For any given request to your API, data recorded is strictly limited to:

  • Request method (GET, POST, PUT, etc.)
  • Endpoint requested
  • User agent
  • Client IP address (optional)
  • Timestamp of the request
  • Response status code
  • Response time
  • Hostname of API
  • API framework in use (FastAPI, Flask, Express, etc.)

Data collected is only ever used to populate your analytics dashboard, and never shared with a third-party. All stored data is pseudo-anonymous, with the API key the only link between you and your logged request data. Should you lose your API key, you will have no method to access your API analytics.

View our full privacy policy and frequently asked questions on our website.

Data Deletion

At any time, you can delete all stored data associated with your API key by going to apianalytics.dev/delete and entering your API key.

API keys and their associated logged request data are scheduled to be deleted after 6 months of dashboard inactivity, or if 3 months have elapsed without logging a request.

Active Monitoring

Active endpoint monitoring can be set up by heading to apianalytics.dev/monitoring to enter your API key. Our servers will regularly ping chosen endpoints to monitor uptime and response time.

Limitations

In order to keep the service free, up to 1 million requests can be stored against an API key. This is enforced as a rolling limit; old requests will be replaced by new requests. If your API would rapidly exceed this limit, we recommend you try other solutions or check out self-hosting.

Self-Hosting

The project can be self-hosted by following the guide.

Please note: Self-hosting is still undergoing testing, development and further improvements to make it as easy as possible to deploy. It is currently recommended that you avoid self-hosting for production use.

Contributions

Contributions, issues and feature requests are welcome.

  • Fork it (https://github.com/tom-draper/api-analytics)
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (`git

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Goactixanalyticsapiapi-analytics

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架