RESTfull API Client Application - Richardson Maturity Model - The Right Way

Context

I am working on a RESTfull API using Symfony2 (my API implementation is mainly based on FOSRestBundle and Serializer , I also introduced Hateoas to reach the third level  Richardson's Maturity Model (both Level 1 and 2 are fully respected).

My question is

My problem is with my Symfony2 client application, I use the Guzzle library to request my API, but I am struggling with how I should manage the relationship between resources.

Let’s make it more clear, here’s a corresponding example,

Suppose I have resource Aone associated with resource B. The main client-side function I'm working on is creating a new resource A, but creating A also means creating a related one B resource. The client application should focus on the API method, which has the following signature / route: <POST> /api/resourceA.

But since creation Arequires creation Band is associated with it A, I must then mark " <POST> /api/resourceB", and then get the answer 201with the associated one B resource, use this link to call the appropriate resource BGET method to get Id(or get it from the answer POST). add the identifier to the appropriate one ressource A, and then you can call my method <POST> /api/resourceA(new).

, , -. 1 .

- , ?

TL; DR

, ,

  • A B
  • , , Hateaous ( GET PUT/POST).

, ( ),

  • POST B
  • B A
  • POST A
  • A
  • B

REST " ". , -, :

  • /library/ ( Symfony2), , , API- Rest()?
  • , , .
+3
1

A B (A B), . - <POST> /api/resourceAB.

0

Source: https://habr.com/ru/post/1523549/


All Articles