• This repository has been archived on 30/Jan/2019
  • Stars
    star
    249
  • Rank 162,987 (Top 4 %)
  • Language
    Clojure
  • Created over 12 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Makes working with URLs in Clojure and ClojureScript easy

url Travis CI status

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

"Installation"

url is available in Clojars. Add this :dependency to your Leiningen project.clj:

[com.cemerick/url "0.1.1"]

Or, add this to your Maven project's pom.xml:

<repository>
  <id>clojars</id>
  <url>http://clojars.org/repo</url>
</repository>

<dependency>
  <groupId>com.cemerick</groupId>
  <artifactId>url</artifactId>
  <version>0.1.1</version>
</dependency>

Starting with version 0.1.0, url requires Clojure >= 1.5.0. It provides the same API under ClojureScript (tested with ClojureScript 0.0-1835, and should work well with any later revision).

Usage

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

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

url will also accept additional paths to be resolved against the path in the base URL:

=> (url "https://api.twitter.com/")
#cemerick.url.URL{:protocol "https", :username nil, :password nil,
                  :host "api.twitter.com", :port -1, :path "/", :query nil,
                  :anchor nil}
=> (url "https://api.twitter.com/" "1" "users" "profile_image" "cemerick")
#cemerick.url.URL{: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 (url "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 url does not perform any url-encoding of paths. Use cemerick.url/url-encode to url-encode any paths/path components prior to passing them to url. e.g.:

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

Need Help?

Ping cemerick on freenode irc or twitter if you have questions or would like to contribute patches.

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.

More Repositories

1

jsdifflib

A javascript library for diffing text and generating corresponding HTML views
JavaScript
1,452
star
2

friend

An extensible authentication and authorization library for Clojure Ring web applications and services.
Clojure
1,157
star
3

austin

The ClojureScript browser-REPL rebuilt stronger, faster, easier.
Clojure
511
star
4

clojure-type-selection-flowchart

Flowchart for choosing the right Clojure type definition form
235
star
5

clojurescript.test

A maximal port of `clojure.test` to ClojureScript. DEPRECATED
Clojure
166
star
6

double-check

@reiddraper's test.check (nΓ©e simple-check), made Clojure/ClojureScript-portable DEPRECATED
Clojure
125
star
7

bandalore

A Clojure client library for Amazon's Simple Queue Service (SQS)
Clojure
77
star
8

nrepl-python-client

A Python client for nREPL, the Clojure network REPL
Python
49
star
9

friend-demo

An ΓΌber-demo of most (eventually, all) that Friend has to offer.
Clojure
37
star
10

clojure-web-deploy-conj

A sample Clojure web application project with support for deployment via pallet and jclouds, as presented at the first Clojure Conj in October, 2010.
Clojure
29
star
11

pprng

portable pseudo-random number generators for Clojure and ClojureScript DEPRECATED
HTML
26
star
12

raposo

25
star
13

stopthatrightnow

HTML
12
star
14

ancap-news

A Chrome/Firefox extension to help bring out hacker news' true colors
JavaScript
11
star
15

yonder

Go eval this Clojure[Script] over there.
Clojure
8
star
16

silly-shootout

Shell
7
star
17

immutant-aws

WIP WIP WIP β€” automating AMI baking + vagrant usage of clustered immutant
Shell
5
star
18

mostly-lazy

Clojure
5
star
19

cemerick-mvn-repo

Chas Emerick's micro-mvn-repository
4
star
20

s3-photo-archiver

archival storage of photo and video media in AWS S3
Java
3
star
21

bollocks

2
star
22

.emacs.d

Portable emacs configuration file.
Emacs Lisp
2
star
23

Lemerick

2
star
24

this-plt-life

a little "script" for downloading all the gifs from http://this-plt-life.tumblr.com/
Clojure
2
star
25

utc-dates

A simple date formatting/parsing library.
Clojure
1
star
26

clutch-clojurescript

1
star
27

ikvm-mono-exit-hang

Reproduction of bug described here: https://sourceforge.net/mailarchive/forum.php?thread_name=B75FBFED-D6C4-4E19-BD7E-B4F331F3C3E9%40snowtide.com&forum_name=ikvm-developers
C#
1
star