metosin / metosin/compojure-api

Compile to non-linear routing strategies

Open
#467 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Clojure
Stars
1.1k
Forks
146
PR merge metrics
No merged PRs in 30d

Description

These will probably have to be different than reitit's since route conflicts are idiomatic. We'll probably want more types of routing between trie and linear.

I think routing based on HTTP verb is a good start;

e.g.,

```clojure
(context "/foo" []
(GET "/bar" [] (ok 1))
(POST "/bar" [] (ok 1))
(PUT "/bar" [] (ok 1))
(PATCH "/bar" [] (ok 1)))
=>
(context "/foo" req
(case (get-http-verb req)
:GET (GET "/bar" [] (ok 1))
:POST (POST "/bar" [] (ok 1))
:PUT (PUT "/bar" [] (ok 1))
:PATCH (PATCH "/bar" [] (ok 1))))
```

This could probably be achieved at runtime by reifying some of the structure of a route macro at runtime.

Maybe a static context can communicate to its endpoints to return a data representation of themselves instead of expanding to compojure and the static context can compile a more efficient router.

This could be accomplished more dynamically by having `context` bind a dynamic variable and expanding endpoints to code that checks for this variable to decide whether to return a data representation or a compojure route.

This has the advantage over static transformation under a `context` of working even if the endpoint is not directly under the `context` (say, separated by a function call).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by tracing the `context` and HTTP verb endpoint macros, then inspect how they expand into Compojure routes and how separated endpoint functions are handled. Done means supporting a more efficient non-linear routing strategy, including HTTP-verb routing, without losing routes outside the immediate `context`.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.