Finding recommendations for best RestKit / CoreData mapping and JSON structure for shallow routes

I am developing a CoreData iOS application supported by the REST API (Rails) supporting small routes. Since there are a lot of objects on the chart, I would like the REST GET to not include many nested results and instead simply contain the links that RestKit uses to establish (erroneous) relationships. Then I will use shallow routes to query individual (or groups) of objects as needed.

Assuming I have a one-to-many data model (↔>), such as A ↔> B, I have:

RKEntityMapping *a_mapping = [RKEntityMapping mappingForEntityForName:@"A" inManagedObjectStore:managedObjectStore];
[a_mapping addAttributeMappingsFromDictionary:@{@"a_id" : @"aId", ...}];
a_mapping.identificationAttributes = @[@"aId"];

RKEntityMapping *b_mapping = [RKEntityMapping mappingForEntityForName:@"B" inManagedObjectStore:managedObjectStore];
[b_mapping addAttributeMappingsFromDictionary:@{@"b_id" : @"bId", ...}];
b_mapping.identificationAttributes = @[@"bId"];

[a_mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"bs" toKeyPath:@"bs" withMapping:b_mapping]];

I have these routes:

NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);

RKResponseDescriptor *a_ResponseDescriptor;
a_ResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:a_mapping method:RKRequestMethodGET pathPattern:@"/A/:aId" keyPath:@"A" statusCodes:statusCodes];

RKResponseDescriptor *b_ResponseDescriptor;
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
b_ResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:b_mapping method:RKRequestMethodGET pathPattern:@"/B/:bId" keyPath:@"B" statusCodes:statusCodes];

[[RKObjectManager sharedManager] addResponseDescriptor:a_ResponseDescriptor];
[[RKObjectManager sharedManager] addResponseDescriptor:b_ResponseDescriptor];

I have a few related questions:

  • JSON "A", RestKit "B"?

  • , B ( A), JSON "B", RestKit "A '?

  • / RestKit?

(A → B), , . , /A/ 1.json - :

{"a": {"a_id":1, "bs":[{"b_id": 2}, {"b_id": 3}]}}

B/2.json :

{"b": {"b_id":2, "a_id": 1}}

- :

{"b": {"b_id":2, "a": {"a_id": 1}}} 

? / .

+3
2

, , :

  • RKRelationshipMappings
  • JSON A B. Ex. { "b": { "b_id": 2, "a": { "a_id": 1}}}

, iOS-, HTTP, . , .

0

- . RestKit , , . , , - RestKit "" ( , ), , .

JSON /A/1.json A B s.

B/2.json B ( A, ). , "", JSON. RKRelationshipMapping B, .

, B, " stubbing" A, A, B.

, . 1 , , RestKit , , JSON ( JSON , -).

+1

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


All Articles