architect/_archive/2025-11-26-cleanup/cifra/07_API_AND_INTEGRATION.md

CIFRA — API и интеграции

Версия: 2.0.0
Дата: 2025-11-10


REST API

Auto-generated endpoints

Для каждой Entity автоматически создаются:

GET    /api/contacts       - List
POST   /api/contacts       - Create
GET    /api/contacts/:id   - Read
PUT    /api/contacts/:id   - Update
DELETE /api/contacts/:id   - Delete

Filtering (CQL)

GET /api/contacts?filter={
  "status": "active",
  "email": {"$regex": ".*@gmail.com"},
  "created_at": {"$days_ago": 30}
}

Операторы:
- Comparison: $gt, $lt, $in, $between
- String: $regex, $contains, $startswith
- Date: $date_gt, $days_ago, $this_month
- Logical: $and, $or, $not

Sorting & Pagination

GET /api/contacts?sort=-created_at&limit=50&offset=100

Event System

Emit events

from cifra.events import event_bus

await event_bus.emit('entity.Contact.created', {
    'id': contact.id,
    'email': contact.email
})

Subscribe to events

from cifra.events import subscribe

@subscribe('entity.Contact.created')
async def send_welcome_email(event):
    contact = event.payload
    await email_service.send(
        to=contact['email'],
        template='welcome'
    )

WebHooks

webhooks:
  stripe:
    url: /api/webhooks/stripe
    events: [payment.success, payment.failed]

  github:
    url: /api/webhooks/github
    events: [push, pull_request]

GraphQL (будущее)

query {
  contacts(filter: {status: "active"}) {
    id
    name
    email
    company {
      name
    }
  }
}

Следующий документ: UI_AND_THEMES.md →