Make the HTTP feature more flexible to foster easy migrations
See original GitHub issueAs @fedefernandez @raulraja suggested, we should focus not only on greenfield projects and also on existing projects. So in spite of we considered that the HTTP endpoints didn’t need parameters (because could be inferred), we want to provide enough flexibility to let other projects be migrated into Mu without too many efforts.
As the first step, we should add these parameters to the @http
annotation to let the derived server work as expected:
- HTTP Method: GET, POST, PUT, etc.
- Prefix
- Operation
That along with the hostname and the port set when instantiating the server, would compose the entire endpoint paths.
METHOD http://host:port/prefix/operation
(where the prefix can be composed by several segments)
Issue Analytics
- State:
- Created 5 years ago
- Comments:24 (18 by maintainers)
Top Results From Across the Web
Deployments: Generate Schema File and Content Migrations ...
I could be nice to be able to generate migrations for the changes made in the database from the app, I think a...
Read more >Migration tool - Azure Database for PostgreSQL Flexible Server
The tool automates most of the migration steps to make the migration journey across Azure platforms as seamless as possible.
Read more >Drupal 9 - Acquia
Acquia strives to make migrating, building, running, and extending your Drupal 9 application easy. Learn about our Drupal optimized products.
Read more >Database Migrations: Modifying Existing Databases
Where databases are reasonably simple, this process of modifying existing databases is very simple too: in fact the process can be automated.
Read more >A Simpler SharePoint Migration Tool - ShareGate
SharePoint migration made simple. ... Our Promote feature lets you turn nested subsites into top-level site collections in a couple of clicks. Bulk...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I did some work to implement @fedefernandez’s suggestion for making the HTTP feature more flexible. I effectively hand-rolled what the macro would do (which really was an exercise for me to understand Mu and the HTTP feature a little better), and got it all working. I put what I did on the branch
feature/583-more-http-verbs
if you want to have a look, but be warned it’s in no shape for public consumption really!Going down this road would lead to a very small and tidy macro implementation, but more work for the user to wire this all together.
A couple of points I had:
In allowing the client to define their own routes, I had to make the
F
concrete so that it would work with the concrete.route[IO]
call. I don’t think this is an issue on its own. It may be possible to keep the type constructor abstract, but I couldn’t see an immediate way to do this, but I didn’t spend much time on it.This felt more important than my previous point: By asking for implicits, by their nature, you can only ever have one type that matches, so if you have multiple routes that have the same signature, it’s not immediately clear that this can be done, or at least in a simple way. For example, if you have a service made with the following definition (I’m making this up but hopefully it’s realistic enough):
Then we’d expect two different pairs of implicits with the same type for these:
Every logical parameterless ‘get’ (lowercase) is going have that same
PartialFunction
signature. These would need to be differentiated some way. Ideas such ascould work, but these don’t feel natural from a user’s point of view.
Similary, a RESTful style for other definitions throw up similar discussions:
These fit very nicely into the REST model for POST/PUT and DELETE, but there’s no direct translaction due to the fact the implicits required would clash.
I’m still very new to this application, so perhaps I’ve missed something big, but would be interested to get some other thoughts on this. I do wonder if going down this road means hiding too much about the HTTP interface to be useful, and it seems like @rafaparadela’s suggested commit may get around some of these limitations.
@rafaparadela instead of adding new configuration params or extra complexity to our http definitions I suggest re-using the http4s types. Let me explain it with an example.
Suppose you have the following service:
We could ask for the following implicits in the macro:
But providing some default values. For example, for the first one could be something like in the macro def:
Then, the only thing we need to do is compose those implicits with the service function:
This will allow the users to define their owns routes and their own responses, based on the types. For example, for the first case, suppose you want to have a
GET
operation, receiving the param in the path and returning forbidden when the field in the response isfalse
. All you need to do is to provide the right implicits in the scope:Let me know what you think. @juanpedromoreno @raulraja thoughts?