Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign the API #16

Open
Drup opened this issue Apr 18, 2019 · 2 comments
Open

Redesign the API #16

Drup opened this issue Apr 18, 2019 · 2 comments

Comments

@Drup
Copy link
Owner

Drup commented Apr 18, 2019

New WIP API:

type 'a ty
val string : string ty
val int : int ty
val list : 'a ty -> 'a list ty
val option : 'a ty -> 'a option ty
val flag : string -> bool ty
val regex : Re.t -> string ty

type 'a key = ..

val meth : meth key
val hash : 'a ty -> 'a key
val header : string -> 'a ty -> 'a key

type 'a t

val return : 'a -> 'a t
(** Doesn't match anything *)

(** Lookup keys *)

val get : 'a key -> ('a -> 'b t) -> 'b t
val record : 'a key -> 'a t
val check : 'a key -> 'a -> unit t

(** Lookup path *)

val s : string -> unit t
val v : 'a ty -> 'a t
val (/) : 'a t -> 'b t -> ('a * 'b) t

(** Lookup queries *)

val query : string -> 'a ty -> 'a t
@let-def
Copy link

let-def commented Apr 18, 2019

type 'a key = private ..

Maybe? To restrict introduction of new constructors.

@Drup
Copy link
Owner Author

Drup commented Apr 18, 2019

@let-def Precisely, no. I want the concrete implementation of the API to be able to introduce new keys.

  • cohttp would introduce meth/hash/headers
  • an SPA framework would only handle cookies/hash
  • a middleware API would probably introduce some special purpose keys to access the state of other middleware (for instance, auth).

You could track it all via typing + polyvar, but I feel a more lightweight approach does not loose so much safety, and is much nicer to use, and we don't really need extensible function, we can just have:

val match : 'a t -> ('a key -> 'a option) -> Url.t -> 'a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants