{"id":19010292,"url":"https://github.com/railsware/rbroutebuilder","last_synced_at":"2025-04-22T23:12:29.610Z","repository":{"id":15629381,"uuid":"18366200","full_name":"railsware/RBRouteBuilder","owner":"railsware","description":"Build routes without strings and headache","archived":false,"fork":false,"pushed_at":"2014-04-04T08:33:05.000Z","size":434,"stargazers_count":15,"open_issues_count":1,"forks_count":1,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-22T23:12:24.549Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"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/railsware.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}},"created_at":"2014-04-02T12:51:53.000Z","updated_at":"2019-06-16T10:23:11.000Z","dependencies_parsed_at":"2022-09-06T01:30:09.063Z","dependency_job_id":null,"html_url":"https://github.com/railsware/RBRouteBuilder","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2FRBRouteBuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2FRBRouteBuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2FRBRouteBuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/railsware%2FRBRouteBuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/railsware","download_url":"https://codeload.github.com/railsware/RBRouteBuilder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250337946,"owners_count":21414104,"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":[],"created_at":"2024-11-08T19:10:43.290Z","updated_at":"2025-04-22T23:12:29.577Z","avatar_url":"https://github.com/railsware.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"RBRouteBuilder\n=================\n\nRBRouteBuilder provides a mechanism to make routes for requests without headache with strings.\n\nSo instead of\n```objectivec\nNSString *path = [NSString stringWithFormat:@\"users/%@/projects\", userID];\n```\nmight be used\n```\nNSString *path = router().users.withID(userID).projects.path;\n```\n\n[More real example](https://github.com/railsware/RBRouteBuilder/blob/master/README.md#example)\n\n### Installation\n\n```\npod 'RBRouteBuilder'\n```\n\n*Note:* RBRouteBuilder has a quite strange integration mechanism, so it provides a file template to simplify this process.\nIt can be installed by calling `install_templates.sh` script from the repository root\n```bash\ngit clone https://github.com/railsware/RBRouteBuilder.git\ncd RBRouteBuilder\nsh install_templates.sh\n```\n\n### Usage\n\nThere are few things need to be done to start using RBRouteBuilder.\n\n#### Routes definition\n\nFirst of all, protocol with route definitions should be added, also this protocol can have one of the following methods: \n\n`- (instancetype)root;` - returns builder instance with the root path \n\n`- (NSString *)path;` - generates NSString from all called methods\n\n`- (NSString *)URL` - generates NSURL from all called methods\n\nProbable protocol definition\n\n```objectivec\n@protocol Router\n\n- (instancetype)root;\n- (NSString *)path;\n- (NSURL *)URL;\n\n- (instancetype)users;\n- (instancetype)projects;\n\n@end\n```\n\n**Note:** do not worry about implementation, all this stuff will be done by RBRouteBuilder internals\n\n#### Builder instantiation\n\nBuilder should be instantiated by calling method `rb_route_builder` with the root path as a parameter. This method defined at `RouterBulider.h`, so do not forget to import it.\n\nHere is a sample of how it could be done\n\n```objectivec\nstatic inline id\u003cRouter\u003e routeBuilder()\n{\n    return rb_route_builder(@\"http://api.sample.com\");\n}\n```\n\nStatic method `routeBuilder` can have any possible name, but it's return type must conform to the newly created protocol.\nThis rule affords using of chained calls:\n\n```objectivec\nrouteBuilder().users.path;\nrouteBuilder().root.projects.URL;\n```\n\n#### Builder helpers\n\n`RBRouteBuilder` has two helper methods, which might be very useful:\n\n`add(NSString *)` - adds string to the bulider\n\n`withID(NSNumber *)` - adds numeric identifier to the bulider\n\nThis methods also might be defined in the protocol if necessary. They use blocks under the hood and have the same rule as method `routeBuilder` from previous section: to allow method chaining the return type must conform to protocol:\n\n```\n- (id\u003cRouter\u003e (^)(NSString *))add;\n- (id\u003cRouter\u003e (^)(NSNumber *))withID;\n```\n\n#### Xcode Template\n\nXcode template provided by `RBRouteBuilder` can be used to avoid all these routines.\n\n![RBRouteBuilder Xcode template](https://raw.githubusercontent.com/railsware/RBRouteBuilder/master/Templates/template.png).\n\n#### Example\n\nHere is how it might look for dealing with GitHub API routes\n\n```objectivec\n// GHRouter.h\n#import \u003cRBRouteBuilder/RouteBuilder.h\u003e\n\n@protocol GHRouter\n    \u003cNSObject\u003e\n\n@optional\n\n- (instancetype)root;\n- (NSString *)path;\n- (NSURL *)URL;\n\n- (id\u003cGHRouter\u003e(^)(NSString *))add;\n- (id\u003cGHRouter\u003e(^)(NSNumber *))withID;\n\n// User-defined routes\n\n- (instancetype)users;\n- (instancetype)orgs;\n\n@end\n\nstatic id\u003cGHRouter\u003e router()\n{\n    return rb_route_builder(@\"https://api.github.com\");\n}\n\n// ...\n// ...\n// ...\n\nNSURL *orgsURL = router().users.add(@\"AlexDenisov\").orgs.URL;\n// NSURL: /users/AlexDenisov/orgs\nNSString *fullOrgPath = router().root.orgs.add(@\"Railsware\").path;\n// NSString: https://api.github.com/orgs/Railsware\n```\n\n### License\n\nThis project distributed under the MIT license.\n\nSee `LICENSE` for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frailsware%2Frbroutebuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frailsware%2Frbroutebuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frailsware%2Frbroutebuilder/lists"}