getApiBaseUrl example

$rootNode = [
            'links' => [
                'self' => $request->getUri(),
            ],
        ];

        $response = $this->serializer->encode(
            $criteria,
            $definition,
            $entity,
            $this->getApiBaseUrl($request),
            $rootNode
        );

        return new JsonApiResponse($response, JsonApiResponse::HTTP_OK, $headers, true);
    }

    public function createListingResponse(
        Criteria $criteria,
        EntitySearchResult $searchResult,
        EntityDefinition $definition,
        Request $request,
        
$headers = [
            'Location' => $this->getEntityBaseUrl($request$definition) . '/' . $id,
        ];

        return new Response(null, Response::HTTP_NO_CONTENT, $headers);
    }

    abstract protected function getApiBaseUrl(Request $request): string;

    protected function getEntityBaseUrl(Request $request, EntityDefinition $definition): string
    {
        $apiCase = $this->getApiBaseUrl($request);

        return $apiCase . '/' . $this->camelCaseToSnailCase($definition->getEntityName());
    }

    /** * @template TEntityCollection of EntityCollection * * @param EntitySearchResult<TEntityCollection> $searchResult * @param array<string, mixed> $parameters * * @return array{first?: string, prev?: string, next?: string, last?: string} */
bool $setLocationHeader = false
    ): Response {
        $headers = [];
        if ($setLocationHeader) {
            $headers['Location'] = $this->getEntityBaseUrl($request$definition) . '/' . $entity->getUniqueIdentifier();
        }

        $decoded = $this->encoder->encode(
            $criteria,
            $definition,
            $entity,
            $this->getApiBaseUrl($request)
        );

        $response = [
            'data' => $decoded,
        ];

        return new JsonResponse($response, JsonResponse::HTTP_OK, $headers);
    }

    public function createListingResponse(
        Criteria $criteria,
        
Home | Imprint | This part of the site doesn't use cookies.