Comments (9)
Will solution be simmilar to something what serverpod is working on?
// Client that can connect to the pod. var client = Client (‘https://myapi.com/’); // Calling generated client code. var result = await client.example.hello(‘World’); // ‘result’ will be ‘Hello World’.
To chime in, an API like this would be interesting, but for accessing/using those endpoints, I would like to specify the request method type when calling the generated code:
var getResult = await client.example.hello.get(...);
var postResult = await client.example.hello.post(...);
One things that would be very cool would to have the generated client only generate those methods for the supported methods. This would probably be next to impossible to achieve with out some type of static knowledge provided by the developer.
For example, I want to generate the client endpoint that would only be able to execute GET
and POST
requests on the the example/hello
route (the snippet from above). I could provide some hint to the client generator that those are the only two methods the API supports. One could decorate the onRequest
method to convey that information
@FrogClientSupport(['GET', 'POST']); // optional, will generate for all possible methods if not specified.
FutureOr<Response> onRequest(RequestContext context) async {
final method = context.request.method;
if (method == HttpMethod.get) return _get(context);
else if (method == HttpMethod.post) return _post(context);
return Response(statusCode: HttpStatus.methodNotAllowed); // for non-generated clients
}
And the resulting resulting client should never generate methods that are not in the decorator
// The method 'put' isn't defined for the type 'DartFrogClient'.
// Try correcting the name to the name of an existing method, or defining a method named 'put'.
var putResult = await client.example.hello.put(...);
Hopefully that makes sense — let me know your thoughts!
from dart_frog.
other idea to checkout: https://pub.dev/packages/mid
mid is a tool to build an end-to-end typesafe API in dart. The tool generates an API server and a client library in addition to handling requests and managing communication between the server and the client.
https://pub.dev/packages/mid#motivation
Motivation
To have the ability to call the backend code from the frontend in a type safe manner and as simple as calling a function in pure Dart.
Note: mid is not intended to generate a REST API, but to generate an API server that can be seamlessly used by a Dart or Flutter frontend with a minimal effort.
from dart_frog.
I think that decoration (or anything else) would be necessary anyway to generate the API Docs #152 too...
from dart_frog.
I like the convention-based concept of route handlers in Next.js 13 coupled with the codegen influences of Serverpod.
FutureOr<Response> get(request: Request) async {} FutureOr<Response> post(request: Request, String name) async {}In the application, the client-generated API would resolve to
var getResult = await client.example.hello.get(...); var putResult = await client.example.hello.put(...);Fwiw that’s how the client generation POC worked and it was what the team was leaning towards since it requires no additional metadata/annotations.
Just to be clear. so to avoid adding annotations there are going to be breaking changes in the way that requests are handled in each route based on above concept? meaning instead of having a single onRequest
for each route there can be request handler functions for each HTTP methods.
from dart_frog.
Will solution be simmilar to something what serverpod is working on?
// Client that can connect to the pod.
var client = Client (‘https://myapi.com/’);
// Calling generated client code.
var result = await client.example.hello(‘World’);
// ‘result’ will be ‘Hello World’.
from dart_frog.
I like the convention-based concept of route handlers in Next.js 13 coupled with the codegen influences of Serverpod.
FutureOr<Response> get(request: Request) async {} FutureOr<Response> post(request: Request, String name) async {}In the application, the client-generated API would resolve to
var getResult = await client.example.hello.get(...); var putResult = await client.example.hello.put(...);
Fwiw that’s how the client generation POC worked and it was what the team was leaning towards since it requires no additional metadata/annotations.
from dart_frog.
I have some experience creating a dart API client code generator in this project (fantom).
Is there a plan for this? I would very much like to contribute to this
@felangel @renancaraujo
from dart_frog.
I like the convention-based concept of route handlers in Next.js 13 coupled with the codegen influences of Serverpod.
FutureOr<Response> get(request: Request) async {}
FutureOr<Response> post(request: Request, String name) async {}
In the application, the client-generated API would resolve to
var getResult = await client.example.hello.get(...);
var putResult = await client.example.hello.put(...);
from dart_frog.
I like the convention-based concept of route handlers in Next.js 13 coupled with the codegen influences of Serverpod.
FutureOr<Response> get(request: Request) async {} FutureOr<Response> post(request: Request, String name) async {}In the application, the client-generated API would resolve to
var getResult = await client.example.hello.get(...); var putResult = await client.example.hello.put(...);Fwiw that’s how the client generation POC worked and it was what the team was leaning towards since it requires no additional metadata/annotations.
Makes sense! It also seems like this pattern would play nice with OpenAPI documentation and use in non-dart projects, since it produces a "normal" REST api.
from dart_frog.
Related Issues (20)
- fix: No active package dart_frog_cli after activation HOT 2
- feat: Add support for middleware testing on `dart_frog_test` HOT 2
- fix: Using too much memory HOT 3
- docs: configure a `.vscode/launch.json` to execute "Dart Frog: Start and Debug Development Server" command HOT 1
- fix: ./pubspec_overrides.yaml generated with \ on windows breaks docker build. HOT 3
- fix: pre hook script: Null check operator used on a null value HOT 13
- fix: Flutter web CORS request handling HOT 2
- fix: VSCode With Incompatible `dart_frog` Version Causes Poor Performance HOT 5
- docs: include `hostname` daemon documentation
- How can we use frog as a android application also server run in background HOT 1
- fix: Test cases failing in dart_frog_cli while running dart test(OS errors)
- fix: need clarity around static files HOT 6
- chore: Dart Frog CLI 1.2.0 release
- max number of websockets HOT 3
- fix: Concurrency Issues HOT 2
- CI / CD Workflow Examples HOT 2
- Dart frog support Isolates ? HOT 2
- docs: Add Globe to Deployment section in Docs
- How to inject variables into context in a certain route HOT 4
- feat: allow $ in `new` commands
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 dart_frog.