{"id":15050684,"url":"https://github.com/pinarol/serviceproxy","last_synced_at":"2026-02-02T11:39:22.172Z","repository":{"id":254742899,"uuid":"847413963","full_name":"pinarol/ServiceProxy","owner":"pinarol","description":"Do not implement REST API calls, declare the method signatures and they'll just work.","archived":false,"fork":false,"pushed_at":"2024-09-15T15:06:16.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T02:29:37.405Z","etag":null,"topics":["json","json-mapper","json-mapping","networking","nsproxy","objc-runtime","objective-c","rest","rest-api","runtime","service"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pinarol.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-25T18:50:04.000Z","updated_at":"2024-09-15T15:06:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"96705fbc-0c5e-4eb0-a9ba-0bbf07a9052c","html_url":"https://github.com/pinarol/ServiceProxy","commit_stats":null,"previous_names":["pinarol/serviceproxy"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pinarol/ServiceProxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinarol%2FServiceProxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinarol%2FServiceProxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinarol%2FServiceProxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinarol%2FServiceProxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pinarol","download_url":"https://codeload.github.com/pinarol/ServiceProxy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinarol%2FServiceProxy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261628876,"owners_count":23186923,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","json-mapper","json-mapping","networking","nsproxy","objc-runtime","objective-c","rest","rest-api","runtime","service"],"created_at":"2024-09-24T21:28:54.986Z","updated_at":"2026-02-02T11:39:22.097Z","avatar_url":"https://github.com/pinarol.png","language":"Objective-C","readme":"# ServiceProxy\n\nServiceProxy API allows you to write REST API calls with minimal code. No boilerplate guaranteed.\n\nWrite ZERO code to,\n- Serialize the request from an object.\n- Deserialize the response into an object.\n- Even making the actual network call!\n\nExample:\n\nSamplePaymentsService.h\n\n```\ntypedef void (^PNRCreatePrePaymentRecordRequestCompletion)(NSError *error, PNRCreatePrePaymentRecordResponse *response);\n\n@interface SamplePaymentsService : PNRService\n\n// Declare your service call. What kind of request it takes and what kind of response it returns.\n- (void)createPrePaymentRecordWithRequest:(PNRCreatePrePaymentRecordRequest *)request completion:(PNRCreatePrePaymentRecordRequestCompletion)completion;\n\n@end\n```\n\nSamplePaymentsService.m\n\n```\n\n@implementation SamplePaymentsService\n\n- (void)createPrePaymentRecordWithRequest:(PNRCreatePrePaymentRecordRequest *)request completion:(__strong PNRCreatePrePaymentRecordRequestCompletion)completion {\n\n\n   // Yes, you are seeing right. There's no code here!\n   // Because you don't need any. This is the magic of ServiceProxy.\n\n\n}\n\n- (PNRServiceInfo *)serviceInfoForSelector:(SEL)selector\n{\n    if (selector == @selector(createPrePaymentRecordWithRequest:completion:))\n    {   // return the endpoint and the HTTP method\n        return [[PNRServiceInfo alloc] initWithUrl:@\"payment/pre-record\" requestMethod:PNRRequestMethodPOST];\n    }\n    return nil;\n}\n\n```\n\nSample response:\n\n```\n\n@interface PNRCreatePrePaymentRecordResponse : PNRResponse\n\n@property (nonatomic, strong) PNRPaymentRecord *record;\n\n@end\n\n@implementation PNRCreatePrePaymentRecordResponse\n\n   // You are seeing right. There's no code here as well! \n   // No need for any parsing or JSON mapping.\n\n@end\n\n```\n\nHow do i make the actual service call?\n\nConfigure your PNRServiceManager just once with a simple config object that conforms to `PNRServiceConfiguration`. Here, you pass your host url and stuff.\n```\n    [PNRServiceManager sharedManager].configuration = [MockServiceConfiguration new];\n```\n\nCreate your `SamplePaymentsService` with the help of `PNRServiceManager`. Pass a network manager that conforms to `PNRNetworkManager`.\n\n```\n    SamplePaymentsService *service = [[PNRServiceManager sharedManager] serviceForClass:[SamplePaymentsService self] withCustomNetworkManager:myNetworkManager.shared];\n```\n\nThat's it. Now you can call your service.\n```\n    // Build your request as necessary.\n    PNRCreatePrePaymentRecordRequest *request = [PNRCreatePrePaymentRecordRequest new];\n    request.values = ...;\n    request.vendorId = ...;\n    \n    // Make the request.\n    [service createPrePaymentRecordWithRequest:request completion:^(NSError *error, PNRCreatePrePaymentRecordResponse *response) {\n    \n\n        // response is fully parsed as `PNRCreatePrePaymentRecordResponse` and ready to use! Like magic!\n\n        \n    }];\n```\n\n### Okay. But how does it work?\n\nAll this works with the help of Objective-C runtime and [NSProxy](https://developer.apple.com/documentation/foundation/nsproxy). Basically, every service call is handled by the `PNRServiceProxy` and its `forwardInvocation:` method. It reads your method's invocation data to learn what your response and request object are, what completion should be called after the network call, etc. It serializes the request, makes the request; and once it finishes, populates the response for you!\n\nCheck out the unit tests(`ServiceManagerTests`) to see the real life `SamplePaymentsService` implementation.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinarol%2Fserviceproxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpinarol%2Fserviceproxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinarol%2Fserviceproxy/lists"}