Aller au contenu

XCore API Contract v1

The API contract is a construction rule checked in development and CI. It does not add a response-validation layer to production requests.

Success responses

A successful response containing a payload exposes it under data.

{"data":{"id":42}}

Collections use data as an array. Paginated collections additionally expose pagination with page, limit, total and pages. page starts at 1 and limit is between 1 and 100.

204 No Content responses have an empty body.

Errors

Errors expose one error object containing a stable code and a message suitable for the client/i18n layer.

{"error":{"code":"RESOURCE_NOT_FOUND","message":"common.resource_not_found"}}

Validation errors use HTTP 422 and add a non-empty violations object indexed by property. _global is reserved for validation errors not attached to one field.

{
  "error": {
    "code": "VALIDATION_FAILED",
    "message": "common.validation_failed",
    "violations": {
      "email": "validation.email.invalid",
      "_global": "validation.invalid_state"
    }
  }
}

HTTP conventions

  • GET: read, normally 200.
  • POST: create, normally 201; actions may return another documented success status.
  • PUT: complete update, normally 200.
  • PATCH: partial update or explicit targeted action, normally 200.
  • DELETE: deletion without payload, 204.
  • 400: technically malformed request.
  • 401: authentication required or invalid.
  • 403: authenticated but forbidden.
  • 404: resource not found.
  • 409: conflict with current resource/business state.
  • 422: syntactically valid payload rejected by validation.
  • 500: unexpected server error; production responses must not expose technical details.

Query conventions

Common collection parameters are page, limit, search, sort and order. order accepts asc or desc. Business filters remain module-specific.

Runtime boundary

DTOs, Symfony validation, serialization and normal HTTP error handling belong to runtime when required by the application. Contract conformance checking belongs to XCore\\Tooling and therefore to autoload-dev only.

Development and CI enforcement

Contract conformance is checked by:

php bin/console xcore:contract:check

The command is part of the shared quality pipeline:

composer tests
  -> fix
  -> contract
  -> lint
  -> static analysis
  -> unit tests
  -> functional tests

A contract violation returns a non-zero exit code and stops the pipeline before the later checks. The temporary _contract endpoints used to validate the checker itself are not part of the XCore runtime and were removed after Contract v1 qualification.

Until the first runtime module registers real contract probes, the checker reports that Contract v1 is ready with no registered endpoints and exits successfully.