Map url parameters to objects using RESTKit

后端 未结 2 1986
轮回少年
轮回少年 2020-12-10 06:07

is there a way to map the parameters in an URL to the results?

I got a rest service where the user can search something by its ID. The path is search/:id

2条回答
  •  自闭症患者
    2020-12-10 06:39

    You want to use the path pattern you specify in your response descriptor. Then you want to use routing (RKRoute) and metadata during your mapping. The metadata includes a routing section which gives access to the parameters extracted from the URL path.

    Some info on metadata here (the docs are a little lacking).

    In your mapping you want to use:

    @metadata.routing.parameters.id
    

    As the mapping source key path.


    To make routing work you need to add the route to your object manager:

    [manager.router.routeSet addRoute:...
    

    And then you need to make the request in a way that means the route is used, like getObjectsAtPathForRouteNamed:object:parameters:success:failure:.

提交回复
热议问题