Diferencia entre revisiones de «Subrecursos API Platform»

De Wiki Proyectos Beta
Ir a la navegación Ir a la búsqueda
([feat] Add information Subrecursos API Platform)
 
(feat: add SEO)
 
(No se muestran 3 ediciones intermedias del mismo usuario)
Línea 1: Línea 1:
= Descripción =
== Descripción ==


= Recursos ==
== Recursos ==


* Documentación oficial: [https://api-platform.com/docs/core/subresources/ EN]
* Documentación oficial: [https://api-platform.com/docs/core/subresources/ EN]


= Ejemplo =
== Ejemplos API Platform 3 ==


== Ejemplo1 ==
=== Ejemplo 1 ===
 
#[ApiResource(
    uriTemplate: '/answers/{id}/related_questions.{_format}',
    uriVariables: [
        'id' => new Link(fromClass: Answer::class, fromProperty: 'relatedQuestions')
    ],
    operations: [new GetCollection()]
)]
 
=== Ejemplo 2 ===
 
#[ApiResource(
    uriTemplate: '/companies/{companyId}/employees/{id}',
    uriVariables: [
        'companyId' => new Link(fromClass: Company::class, toProperty: 'company'),
        'id' => new Link(fromClass: Employee::class),
    ],
    operations: [ new Get() ]
)]
 
=== Ejemplo 3 ===
 
#[ApiResource(
    uriTemplate: '/companies/{companyId}/employees',
    uriVariables: [
        'companyId' => new Link(fromClass: Company::class, toProperty: 'company'),
    ],
    operations: [ new GetCollection() ]
)]

Revisión actual - 08:09 1 sep 2024

Descripción

Recursos

  • Documentación oficial: EN

Ejemplos API Platform 3

Ejemplo 1

#[ApiResource(
   uriTemplate: '/answers/{id}/related_questions.{_format}',
   uriVariables: [
       'id' => new Link(fromClass: Answer::class, fromProperty: 'relatedQuestions')
   ], 
   operations: [new GetCollection()]
)]

Ejemplo 2

#[ApiResource(
   uriTemplate: '/companies/{companyId}/employees/{id}',
   uriVariables: [
       'companyId' => new Link(fromClass: Company::class, toProperty: 'company'),
       'id' => new Link(fromClass: Employee::class),
   ],
   operations: [ new Get() ]
)]

Ejemplo 3

#[ApiResource(
   uriTemplate: '/companies/{companyId}/employees',
   uriVariables: [
       'companyId' => new Link(fromClass: Company::class, toProperty: 'company'),
   ],
   operations: [ new GetCollection() ]
)]