
    /**
     * Creates a new {{ entity }} entity
     *
{% if 'annotation' == format %}
     * @Route("/", name="{{ route_name_prefix }}_create")
     * @Method("POST")
{% endif %}
     *
     * @Hydra\Operation(
     *   expect = "{{ namespace }}\Entity\{{ entity }}",
     *   status_codes = {
     *     "201" = "If the {{ entity }} entity was created successfully."
     * })
     *
     * @return {{ namespace }}\Entity\{{ entity }}
     */
    public function collectionPostAction(Request $request)
    {
        $entity = $this->deserialize($request->getContent(), '{{ namespace }}\Entity\{{ entity }}');

        if (false !== ($errors = $this->validate($entity))) {
            return $errors;
        }

        $em = $this->getDoctrine()->getManager();
        $em->persist($entity);
        $em->flush();

{% if 'entity_get' in actions %}
        $iri = $this->generateUrl('{{ route_name_prefix }}_retrieve', array('id' => $entity->getId()), true);

        $response = new JsonLdResponse(
            $this->serialize($entity),
            201,
            array('Content-Location' => $iri)
        );

        return $response;
{% else %}
        return new JsonLdResponse('', 201);
{% endif %}
    }


    /**
     * Creates a new {{ entity }} entity
     *
{% if 'annotation' == format %}
     * @Route("/", name="{{ route_name_prefix }}_create")
     * @Method("POST")
{% endif %}
     *
     * @Hydra\Operation(
     *   expect = "{{ namespace }}\Entity\{{ entity }}",
     *   status_codes = {
     *     "201" = "If the {{ entity }} entity was created successfully."
     * })
     *
     * @return {{ namespace }}\Entity\{{ entity }}
     */
    public function collectionPostAction(Request $request)
    {
        $entity = $this->deserialize($request->getContent(), '{{ namespace }}\Entity\{{ entity }}');

        if (false !== ($errors = $this->validate($entity))) {
            return $errors;
        }

        $em = $this->getDoctrine()->getManager();
        $em->persist($entity);
        $em->flush();

{% if 'entity_get' in actions %}
        $iri = $this->generateUrl('{{ route_name_prefix }}_retrieve', array('id' => $entity->getId()), true);

        $response = new JsonLdResponse(
            $this->serialize($entity),
            201,
            array('Location' => $iri, 'Content-Location' => $iri)
        );

        return $response;
{% else %}
        return new JsonLdResponse('', 201);
{% endif %}
    }

Set both the Location and the Content-Location header in a 201 response
Set both the Location and the Content-Location header in a 201 response
