GithubHelp home page GithubHelp logo

uritemplatestring's Introduction

trail icon

UriTemplateString Build status NuGet version codecov.io codefactor

Parses URI Templates into a friendly object structure.

Installation

Get from nuget.org

install-package UriTemplateString

Usage

Simply cast a string to UriTemplateString.

var template = (UriTemplateString)"/base/users{/page:2}{?name}";

Now you can inspect the structure of the template

template.Parts.Length == 3;

// access literal parts
var literal = template.Parts[0] as Literal;
literal.ToString() == "/base/users";

// access parts with modifier
var pageSeg = template[1] as Expression;
(pageSeg.Modifier as MaxLength).MaxLength == 2;

// access variables and operator
var query = template.Parts[2] as Expression;
query.Operator.Equals(Operator.QueryComponent);
query.Variables[0].Name == "name";

And do simple operations

// concatenate templates (and raw strings)
template += "{&rest*}";
// produces /base/users{/page:2}{?name}{&rest*}

// append query
template.AppendQueryParam("rest", explode: true);
// produces /base/users{/page:2}{?name,rest*}

Gotchas

Parsing is implemented using regular expressions so performance can be suboptimal.

Also, currently the expressions are an approximation of the real spec. Quirks possible ahead.

The stencil print icon by Dairy Free Design from The Noun Project

uritemplatestring's People

Contributors

tpluscode avatar asbjornu avatar

Stargazers

Stanislav Prusac avatar Yves Reynhout avatar Figaro - the embedded native XML database for .NET avatar  avatar

Watchers

 avatar James Cloos avatar

Forkers

asbjornu forki

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.