A
A
Abc Edc2015-11-25 23:29:21
JavaScript
Abc Edc, 2015-11-25 23:29:21

How to handle mass update in api and controllers correctly?

If you edited one element, then everything is OK (PUT) some / id
But what if the entity elements on the form are edited in bulk?
Don't spam (PUT) some/id in a loop?
Surely start a separate rest, but how according to GOST should it sound like (PUT) some/mass-update with an array in the body? And the controller in the cycle should the service separately pull for each element from the body?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2015-11-26
@gleber1

Hmm ... Yes, everything is simpler.
Throw packs, and that's all.

/**
 * @Route("/articles")
 * @Method("PUT")
 */
public function putArticlesAction(array $articles)
{
    foreach ($articles as $article) {
        $this->putArticleAction($article);
    }
}

/**
 * @Route("/articles/{article}")
 * @Method("PUT")
 */
public function putArticleAction($article)
{

}

What's the point. Your resource will be not an entity, but a collection of entities.
Similar to the GET method along the /articles path - you get a collection. And PUT'om you change it. DELETE will delete and so on...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question