AgentSkillsCN

Api Pattern Recognition

API 模式识别

SKILL.md

API Pattern Recognition Skill

Purpose

Recognizes API type patterns from URLs, HTTP headers, response bodies, and endpoint structures. This is the core classification engine that determines whether an API is REST, GraphQL, SOAP, or gRPC.

Input

The skill receives an API's URL, HTTP headers, and optionally a response body sample.

Classification Rules

REST API Detection

Confidence: High (>0.8) when 3+ indicators match:

IndicatorWeightPattern
URL path contains /api/0.2/api/v1/resources
URL path contains /v{N}/0.2/v2/payments
Content-Type is application/json0.2Content-Type: application/json
Response is valid JSON object/array0.15{"data": [...]}
Uses RESTful resource naming0.15Nouns: /users, /orders, /payments
Multiple HTTP methods supported0.1GET, POST, PUT, DELETE on same base
Has OpenAPI/Swagger spec0.2/swagger.json, /openapi.yaml
HATEOAS links in response0.1"_links": {"self": {...}}

URL patterns:

code
/api/v1/resources
/api/resources/{id}
/v2/payments
/rest/services/data

Anti-patterns (reduce REST confidence):

  • POST-only endpoint → might be GraphQL or RPC
  • XML response → might be SOAP
  • Binary content → might be gRPC

GraphQL API Detection

Confidence: High (>0.8) when 2+ indicators match:

IndicatorWeightPattern
URL path is /graphql0.4POST /graphql
POST body contains "query" key0.3{"query": "{ users { id } }"}
Response has "data" root key0.2{"data": {"users": [...]}}
Response has "errors" key0.15{"errors": [{"message": "..."}]}
Introspection query works0.3__schema returns types
Single endpoint, all POST0.2Only /graphql endpoint

URL patterns:

code
/graphql
/gql
/api/graphql
/v1/graphql

SOAP API Detection

Confidence: High (>0.8) when 2+ indicators match:

IndicatorWeightPattern
URL ends with .asmx or .svc0.3/service.asmx
Content-Type is text/xml0.3Content-Type: text/xml
Content-Type is application/soap+xml0.3SOAP 1.2
Response contains SOAP envelope0.3<soap:Envelope ...>
WSDL available at ?wsdl0.3https://host/service?wsdl
SOAPAction header present0.2SOAPAction: "urn:action"
Namespace references SOAP0.2xmlns:soap=

URL patterns:

code
/services/PaymentService.asmx
/ws/AccountService.svc
/soap/v1/credit

gRPC API Detection

Confidence: High (>0.8) when 2+ indicators match:

IndicatorWeightPattern
Content-Type is application/grpc0.4gRPC protocol
HTTP/2 protocol0.2Required for gRPC
Port 500510.2Default gRPC port
gRPC reflection works0.3grpc.reflection.v1alpha
Binary protobuf response0.2Non-text response body
grpc-status header0.3grpc-status: 0

URL patterns:

code
host:50051/package.Service/Method

Decision Algorithm

python
def classify(url, headers, body):
    scores = {
        "REST": calculate_rest_score(url, headers, body),
        "GraphQL": calculate_graphql_score(url, headers, body),
        "SOAP": calculate_soap_score(url, headers, body),
        "gRPC": calculate_grpc_score(url, headers, body),
    }

    best_type = max(scores, key=scores.get)
    confidence = scores[best_type]

    if confidence < 0.3:
        return "unknown", confidence

    return best_type, min(confidence, 1.0)

Output Format

json
{
  "api_type": "REST",
  "confidence": 0.85,
  "indicators_matched": [
    "URL contains /api/v1/",
    "Content-Type: application/json",
    "Valid JSON response",
    "RESTful resource naming"
  ],
  "indicators_not_matched": [
    "No HATEOAS links"
  ]
}

Edge Cases

  1. REST-like GraphQL: Some GraphQL APIs are mounted at /api/graphql - check for GraphQL query format in body
  2. JSON SOAP: Modern SOAP can use JSON - check for SOAP envelope markers
  3. REST over gRPC (gRPC-Web): Uses application/grpc-web content type
  4. Hybrid APIs: Some APIs expose both REST and GraphQL - report both with individual confidence scores