Giter VIP home page Giter VIP logo

csuritemplate's Introduction

CSURITemplate

Build Status

CSURITemplate is an Objective-C implementation of RFC6570: URI Template up to Level 4 of the spec.

Example usage:

NSError *error = nil;
CSURITemplate *template = [CSURITemplate URITemplateWithString:@"{?list*}"
                                                         error:&error];
NSDictionary *variables = @{@"list": @[@"red", @"green", @"blue"]};
NSString *uri = [template relativeStringWithVariables:variables error:&error];
assert([uri isEqualToString:@"?list=red&list=green&list=blue"]);

NSURL *baseURL = [NSURL URLWithString:@"http://www.example.com"];
NSURL *URL = [template URLWithVariables:variables relativeToURL:baseURL error:&error];
assert([uri isEqualToString:@"http://www.example.com?list=red&list=green&list=blue"]);

Installation

CocoaPods is the easiest way to use CSURITemplate.

platform :ios, '6.0'
pod 'CSURITemplate'

csuritemplate's People

Contributors

blakewatters avatar jessedc avatar raphweiner avatar segiddins avatar tommymonk avatar wharris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

csuritemplate's Issues

Add Support for Template Matching

I have been planning to deeply add support for URITemplates to RestKit for the last few months. Earlier today I came across CSURITemplate and was thrilled -- you've saved me the effort of having to implement the spec!

One feature that I need to be able to complete my integration is support for matching templates against fully formed URI's. For example, given a template @"/users/{username}/categories" and the URL http://whatever.com/users/blake/categories, evaluate the template as a positive or negative match and return a dictionary containing the matched variables.

I wanted to check in and see if you were interested in merging such a patch were I to tackle the development. It will come in with full documentation, tests and all that jazz and would then become a core dependency of RestKit.

Integration with NSURL

This issue is to discuss potential designs for integrating CSURITemplate with NSURL for constructing relative and absolute URL's built from a pattern.

One design approach might look like the following:

@interface CSURITemplate (URLIntegration)

- (NSURL *)URLWithVariables:(NSDictionary *)variables relativeToURL:(NSURL *)baseURL error:(NSError **)error;

// or

- (NSURL *)URLWithVariables:(NSDictionary *)variables baseURL:(NSURL *)baseURL error:(NSError **)error;

@end

I somewhat hesitate on the relativeToURL: flavor because NSURL changes its behavior based on the presence/absence of a leading '/' when constructing URL's. I think most sane people expect that given a string "/foo/bar" with a baseURL of "http://foobar.com/baz" you would get "http://foobar.com/baz/foo/bar", but you get "http://foobar.com/foo/bar" instead.

Given how templates expansion can easily yield leading slashes, I'd probably argue for just doing an expansion, concatenating the strings, and calling [NSURL URLWithString:] instead of [NSURL URLWithString:relativeToURL:]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.