agentleFS
ivangrynenkoivangrynenko/cursorrules/.cursor/rules/api-standards.mdc

cursorrules / rules

Cursor rule88 starsChanged 13 months agoMITView on GitHub

RESTful API design and documentation standards

The file

We split this api-standards.mdc into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    HTTP Methods: Use proper HTTP methods for operations (GET for retrieval, POST for creation, etc.).

    line 28
  2. Distinctive:

    Status Codes: Use appropriate HTTP status codes to communicate the result of the request.

    line 29
  3. Distinctive:

    Swagger/OpenAPI: Use tools like Swagger for comprehensive API documentation.

    line 32
  4. Distinctive:

    Use HTTPS for all API communications.

    line 36

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
api-standards.mdc
---
description: RESTful API design and documentation standards
globs: *.php, *.js, *.ts
---
# Enhanced API Standards

Ensures consistent API design, documentation, and implementation best practices across PHP, JavaScript, and TypeScript files.

## Rule Details

- **Name:** enhanced_api_standards

- **Description:** Enforce enhanced API design, implementation, and documentation standards

## Filters
- file extension pattern: `\\.(php|js|ts)$`

## Enforcement Checks
- Conditions:
  - pattern `@api\\s+(?!GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD)` – Use standard HTTP methods (GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD) for API endpoints.
  - pattern `function\\s+[a-zA-Z]+Api\\s*\\([^)]*\\)\\s*\\{[^}]*\\}` – negated `(?s)(throw new \\w+Exception|return\\s+(?:\\d{3}|4\\d\\d|5\\d\\d))` – Ensure API functions handle or return errors appropriately using exceptions or HTTP status codes.
  - pattern `(?<!@api\\s+)(?<!\\s+returns\\s+)(?<!\\s+throws\\s+)[A-Z]{3,}(?!\\s+)` – HTTP methods should be prefixed with '@api' for documentation purposes.
  - pattern `\\bresponse\\b(?![^;]*\\.json\\()` – Ensure all API responses are properly formatted, preferably as JSON.

## Suggestions
- Guidance:
**API Best Practices:**
- **HTTP Methods:** Use proper HTTP methods for operations (GET for retrieval, POST for creation, etc.).
- **Status Codes:** Use appropriate HTTP status codes to communicate the result of the request.
- **Versioning:** Implement API versioning to manage changes without breaking existing integrations.
- **Documentation:** 
  - **Swagger/OpenAPI:** Use tools like Swagger for comprehensive API documentation.
  - **Endpoint Descriptions:** Clearly document all endpoints including path, methods, parameters, and possible responses.
- **Authentication & Security:**
  - Implement OAuth, JWT, or similar secure authentication methods.
  - Use HTTPS for all API communications.
- **Rate Limiting:** Implement rate limiting to prevent abuse and ensure fair usage.
- **Error Handling:** 
  - Provide clear, human-readable error messages with corresponding status codes.
  - Implement error logging for debugging purposes.
- **Pagination:** For list endpoints, implement pagination to manage large datasets.
- **Validation:** Validate input data at the API level to ensure data integrity.
- **CORS:** Configure CORS headers if your API is meant to be consumed by web applications from different domains.
- **Monitoring:** Set up monitoring for API performance and usage statistics.

## Metadata
- Priority: high
- Version: 1.2

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.