Kryp
Kryp

Reputation: 1

api platform - Create post requests with nested resources

I'm new to symfony and the api platform and I want to develop an api with specific routes.

I'm looking to do is create a post query with nested resources to add relationships between tables.
example: I have 3 tables (users, periods, articles). I need to create a post request to add a new post with the following structure: URL: api/:userid/:period/item

:userID = user ID
:period = Period name
name = element name

This request must create a new article in my "articles" table by adding the identifier, the name of the period and the name of the article entered as a parameter.

So my question is how do I pass multiple parameters in my path and save them in the database using the api platform?

Thanks in advance !

Upvotes: 0

Views: 816

Answers (1)

Lou
Lou

Reputation: 26

You can use custom routes with API platform, which allow you to create a route that correspond to a custom query => but you need to have these data before setting them in your Api platform path.

First of all, I would use the query builder to create the query you need get the data you need, then you can use your method directly in your entity (more here https://api-platform.com/docs/core/controllers/).

You can set the route you want inside of the path of the route and set the different arguments you need like this:

'path' => '/books/{id}/publication'

here id is your argument coming from your repository function.

Upvotes: 1

Related Questions