[QUESTION] How to create multiple resources
See original GitHub issueHi, I am quite new to api-platform so excuse me if it is a newbie question.
I need to expose an api endpoint to create (or even update) multiple instances of a single resource type.
Something like a POST to /teams_multiple
which accepts a json like:
[
{
"name": "Team 1",
"teamLogo": "logo1.png"
},
{
"name": "Team 2",
"teamLogo": "logo2.png"
},
...
]
Which is the best practice in this case?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
How to create multiple resources when required by terraform
To solve a similar problem, I created a workspace for each environemnt (dev1, dev2, dev3, dev4, and prod), and then a Makefile that...
Read more >Create Multiple Resources - Beginner's Guide to Terraform
This lesson covers different aspects of creating multiple instances of the same resource in Terraform. In it, we'll go over the following concepts:....
Read more >Add resources to your project - Microsoft Support
You can add several types of resources to your project. ... To create a budget resource, select the resource, right-click the resource name,...
Read more >Multiple Resource View - Verbum Support
Open the Multiple Resource menu. Click the drop-down menu to the right of the Multiple Resource icon in the resource panel menu. Select...
Read more >Encouraged students to use multiple resources (e.g., Internet ...
Helping students find answers to questions on their own is also an effective strategy for learning. Find or create a problem for students...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here is an example of my use case. I needed to create many invitations, each one with an email address, at once on the same endpoint.
Firstly, you define your custom operation :
Secondly, you create your DTOs and DataTransformers according to the data needed, in my case
InvitationMultipleRequest
for the input,InvitationMultipleResponse
for the output.DTO InvitationMultipleRequest :
And it’s data transformer :
DTO InvitationMultipleResponse :
Ands it’s data transformer :
Note : I’m doing a single data transformer for each DTO, maybe it’s not the right way to go. If someone has some insight on this I would be more than happy to improve this part of my app and reduce code duplication.
Thirdly, you create your custom controller for implementing the action code, in my case
CreateMultipleAction
Controller. This code contains some other service classes that I won’t share in this post for more clarity. Edit the code and put whatever you need in your controller.And it works like a charm. Thank you API Platform team !
@Simperfit would you have any idea have to do this ? A snippet would be highly appreciated.