Git Product home page Git Product logo

Comments (6)

ikitommi avatar ikitommi commented on August 21, 2024

This should be polymorphic. Alternatives:

1) Use JSON encoder

  • most likely does the job already.
  • requires dependency to JSON library
  • compojure-api does this

2) Multimethod

  • e.g. reitit.core/stringify
  • Easy to implement
  • Value-based, works for all coercion instances
  • Slow(er than Protocol)
  • Adding new types (e.g. LocalTime) requires imperative registration.
    • Extending just for routing, can't (shoudn't) use it elsewhere

3) Protocol

  • e.g. reitit.core/Stringify
  • Easy to implement
  • Value-based, works for all coercion instances
  • Fast(er than Multimethod)
  • Adding new types (e.g. LocalTime) is more declarative
    • Extending just for routing, can't (shoudn't) use it elsewhere
  • bidi does this

4) Coercion/Type-based

  • bijections, defined for all types of coercion
  • both coercion & uncoercion defined in the type meta data
  • works for all use cases, not just routing (where else this is really needed?)
  • parameter type needs to be defined in order to work
  • e.g. with spec tools to keyword?:
(st/spec
  {:spec keyword?
   :description "a bijecting keyword"
   ::encode/string #(name %2)
   ::decode/string #(keyword %2)})

NOTE: qualified keywords as path-parameters need to be url-encoded, as otherwise the / with mess up the generated path. We still could use the generic ::encode/string, just url-encode the results.

from reitit.

malchmih avatar malchmih commented on August 21, 2024

From my point of view, 3rd option (Protocol) is the more natural choice here, since I don't see any other usage of this except for the routing

from reitit.

ikitommi avatar ikitommi commented on August 21, 2024

I think it's the way to go. When/if 4rd is implemented, it can be used instead. Would you like to do a PR?

from reitit.

ikitommi avatar ikitommi commented on August 21, 2024

I have extra time just now, will do this.

from reitit.

ikitommi avatar ikitommi commented on August 21, 2024

#76

from reitit.

ikitommi avatar ikitommi commented on August 21, 2024

fixed in [metosin/reitit-core "0.1.1-20180322.170157-5"].

from reitit.

Related Issues (20)

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.