Giter Club home page Giter Club logo

hype's Introduction

hype

Hypermedia functions for bidi and ring.

Install

Add the following to your project.clj file:

[b-social/hype "1.0.0"]

Documentation

Usage

hype currently provides support for:

  • generating paths or URLs,
  • including URI template parameters, and
  • converting between paths and URLs.

For example:

(require '[ring.mock.request :as ring-mock])
(require '[hype.core :as hype])

(def request (ring-mock/request "GET" "https://localhost:8080/help"))
(def routes 
  [""
   [["/" :index]
    ["/articles" :articles]
    [["/articles/" :article-id] 
     [["" :article]
      [["/sections/" :article-section-id] :article-section]]]]])

(hype/base-url-for request)
; => "https://localhost:8080"

(absolute-path-for routes :index)
; => "/"

(absolute-path-for routes :article
  {:path-params {:article-id 10}})
; => "/articles/10"

(absolute-path-for routes :article
  {:path-template-params {:article-id :article-id}})
; => "/articles/{articleId}"

(absolute-path-for routes :article-index
  {:query-params {:latest true
                  :sort-direction "descending"}
   :query-template-params [:per-page :page]})
; => "/articles?latest=true&sortDirection=descending{&perPage,page}"

(absolute-url-for request routes :index)
; => "https://localhost:8080/"

(absolute-url-for request routes :article
  {:path-template-params {:article-id :articleID}
   :path-template-param-key-fn clojure.core/identity})
; => "https://localhost:8080/articles/{articleID}"

(absolute-url-for request routes :article
  {:path-params {:article-id 10}
   :query-template-params [:include-author :include-images]})
; => "https://localhost:8080/articles/10{?includeAuthor,includeImages}"

(absolute-url-for request routes :article-index
  {:query-params {:latest true
                  :sort-direction "descending"}
   :query-param-key-fn clojure.core/identity
   :query-template-params [:per-page :page]
   :query-template-param-key-fn clojure.core/identity})
; => "https://localhost:8080/articles?latest=true&sort-direction=descending{&per-page,page}"

(absolute-path->absolute-url request "/articles/index.html")
; => "https://localhost:8080/articles"

See the Getting Started guide for more details.

License

Copyright © 2018 B-Social Ltd.

Distributed under the terms of the MIT License.

hype's People

Contributors

tobyclemson avatar jonassvalin avatar

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.