Comments (6)
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.
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.
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.
I have extra time just now, will do this.
from reitit.
from reitit.
fixed in [metosin/reitit-core "0.1.1-20180322.170157-5"]
.
from reitit.
Related Issues (20)
- Muuntaja – OpenAPI integration HOT 1
- Generate swagger top-level definitions for spec & schema
- Malli -> Openapi fails with custom registries HOT 1
- Consider supporting defmulti as handler
- Example projects using reitit.swagger fail to compile
- The server is starting fine but the Swagger UI in the frontend is flashing an error HOT 1
- How about supporting uppercased route HTTP in Ring handler method keywords? HOT 2
- Is it possible to do multi host with reitit-routes? HOT 2
- New version of `@seriousme/openapi-schema-validator` finds new errors HOT 1
- `reitit.coercion.malli` - invalid keys for :responses are accepted
- [Bug] Can't generate swagger with var references HOT 2
- Improve reitit malli humanize data so you can map the errors back to the submitted data.
- Drop Java 8 support
- Resource handler: serve index file without a redirect
- Route data maps ignore meta-merge options in 0.7.0, breaking compatibility HOT 3
- reitit.pedestal/replace-last-interceptor does not replace pedestal router
- Route data validation using malli HOT 1
- Body parameters are always an array HOT 2
- Clojure record in route data is converted to a plain map
- `print-request-diffs` doesn't respect bindings HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reitit.