8000 GitHub - henryw374/uri: basically the same as cemerick.uri but without dependency on ancient clojurescript
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ uri Public
forked from nenadalm/uri

basically the same as cemerick.uri but without dependency on ancient clojurescript

Notifications You must be signed in to change notification settings

henryw374/uri

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clojars Project License

Fork of a fork of a ... tl;dr basically the same as cemerick.uri but without dependency on ancient Clojurescript and a few minor tweaks

Remainder from parent fork README:

This is a library that makes working with URIs in Clojure and ClojureScript a little more pleasant.

Fork of arohner/uri with support for nested parames and clojurescript.

Usage

The cemerick.uri/uri function returns an instance of the cemerick.uri.URI record type that allows you to easily work with each datum within the provided URI:

=> (require '[cemerick.uri :refer (uri uri-encode)])
nil
=> (-> (uri "https://api.stripe.com/v1/charges")
     (assoc :username "vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE")
     str)
"https://vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE:@api.stripe.com/v1/charges"

uri will also accept additional paths to be resolved against the path in the base URI:

=> (uri "https://api.twitter.com/")
#cemerick.uri.URI{:protocol "https", :username nil, :password nil,
                  :host "api.twitter.com", :port -1, :path "/", :query nil,
                  :anchor nil}
=> (uri "https://api.twitter.com/" "1" "users" "profile_image" "cemerick")
#cemerick.uri.URI{:protocol "https", :username nil, :password nil,
                  :host "api.twitter.com", :port -1,
                  :path "/1/users/profile_image/cemerick", :query nil, :anchor nil}
=> (str *1)
"https://api.twitter.com/1/users/profile_image/cemerick"
=> (str (uri "https://api.twitter.com/1/users/profile_image/cemerick" "../../lookup.json"))
"https://api.twitter.com/1/users/lookup.json"

The :query slot can be a string or a map of params:

=> (str (assoc *3 :query {:a 5 :b 6}))
"https://api.twitter.com/1/users/profile_image/cemerick?a=5&b=6"

Note that uri does not perform any uri-encoding of paths. Use cemerick.uri/uri-encode to uri-encode any paths/path components prior to passing them to uri. e.g.:

=> (def download-root "http://foo.com/dl")
#'cemerick.test-uri/download-root
=> (str (uri download-root "/"))
"http://foo.com/"
=> (str (uri download-root (uri-encode "/")))
"http://foo.com/dl/%2F"
=> (str (uri download-root (uri-encode "/logical/file/path")))
"http://foo.com/dl/%2Flogical%2Ffile%2Fpath"

License

Copyright ©2012 Chas Emerick and other contributors

Distributed under the Eclipse Public License, the same as Clojure. Please see the epl-v10.html file at the top level of this repo.

About

basically the same as cemerick.uri but without dependency on ancient clojurescript

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HTML 56.9%
  • Clojure 43.1%
0