Comments (2)
I don't have a lot of experiences with functional programming, but the router makes me think to pattern matching:
// users.gleam
import midas
fn list() -> midas.Response {
// TODO return a midas.Response with the list of users
}
fn get_post(user_id: String, post_id: String) -> midas.Response {
let published = midas.QueryParam(req, "published")
// TODO return a midas.Response with the given post
pub fn router(req: midas.Request, path: List(String)) -> midas.Response {
let is_user_id = midas.String([midas.MinLength(14), midas.MaxLength(14)])
let is_post_id = midas.Integer([midas.Max(999)])
case [req.Verb, path] {
[midas.Get, []] -> list(req, res)
[midas.Get, [user_id, "posts", post_id]] if is_user_id(user_id) && is_post_id(post_id) -> get_post(user_id, post_id)
_ -> midas.error404(req)
}
}
// router.gleam
import midas
import my_app/users
pub fn router(req: midas.Request) -> midas.Response {
case req.SplittedPath {
["users" | rest] -> users.router(req, rest)
_ -> midas.error404(req)
}
}
A limitation is that I don't know how to make post_id
an Int
(and not just a String
to parse).
Maybe it can give you some ideas.
Update: I've read again the README, and I feel stupid to suggest what is already there. Let's just say that I prefer what is in the README to the other suggestions.
from midas.
The pattern matching solution is nice, it's certainly the most simple.
You hit the nail on the head about the integers though. The DSL suggested here gives you more type safety but potentially not worth the overhead.
As mentioned, it can exist as an experimental API for a while because the option of a simple case statement and matching will always exist.
from midas.
Related Issues (20)
- Docker HOT 1
- JSON library HOT 2
- DB access HOT 8
- Create a template to start a new midas project HOT 2
- Input Parsing and error handling HOT 4
- Code reloading HOT 1
- Parameterize type of body in Request type HOT 1
- Put midas Dockerfile in this repo
- Better typing for trapped exits and monitor messages HOT 5
- Supervisors are give a child spec with a run function rather than a spawn_link function HOT 1
- Cookie based Sessions + CSRF
- Flash messages in cookies
- HTML safe templates
- asset compilation
- Logging HOT 2
- Bug reporting
- Document a way to run "mix task"
- Using midas within a Phoenix project HOT 4
- Add Error handling to template example HOT 1
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 midas.