Skip to content

Instantly share code, notes, and snippets.

@shyam-habarakada
Created September 1, 2011 20:23
Show Gist options
  • Save shyam-habarakada/1187171 to your computer and use it in GitHub Desktop.
Save shyam-habarakada/1187171 to your computer and use it in GitHub Desktop.
POST request-response
$ curl -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"first_name":"Jenny","last_name":"McCarthy"}' http://127.0.0.1:3000/patients
HTTP/1.1 200 OK
X-Ua-Compatible: IE=Edge
Etag: "6295adeacd1c3439689e6be85996ddf5"
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
Date: Thu, 01 Sep 2011 20:23:06 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2010-01-10)
X-Runtime: 0.057011
Content-Length: 120
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: _apx-server_session=BAh7BiIPc2Vzc2lvbl9pZCIlNzRmMTE5NTdjMmJlYTg3NWM4ZWM4YWZlZDA3NzVmMTg%3D--68e10e7148f36aa7e337304e133ab9bb4a08af77; path=/; HttpOnly
{"id_str":"16","id":16,"last_name":"McCarthy","date_of_birth":null,"display_name":"Jenny McCarthy","first_name":"Jenny"}
$
@blakewatters
Copy link

If you are exchanging content that does not have a KVC nesting attribute on it, then you need to configure RestKit to infer the appropriate object mapping based on the type of object you are posting:

[RKObjectManager sharedManager].inferMappingsFromObjectTypes = YES;

This will cause RestKit to assume that you are returning content that is of the same type as the content you sent. This arguably could/should be the default behavior, but it blocks the normal KVC lookup semantics.

@shyam-habarakada
Copy link
Author

Blake, what exactly do you mean exchanging content that does not have nested kvc attributes ?

The patient object above is a NSManagedObjcet.

@shyam-habarakada
Copy link
Author

Okay, so I tried this and it seems to have worked. And I think by 'content that does not have KVC nesting attribute', you mean JSON payload without a root element.

For example, content like { "foo":"F", "bar":"B" } instead of { "fooBarContent" : { "foo":"F", "bar":"B" } }

Is that correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment