Code Monkey home page Code Monkey logo

Comments (9)

Luckey-Elijah avatar Luckey-Elijah commented on May 27, 2024 5

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.

GabrielRozendo avatar GabrielRozendo commented on May 27, 2024 3

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.

GabrielRozendo avatar GabrielRozendo commented on May 27, 2024 3

I think that decoration (or anything else) would be necessary anyway to generate the API Docs #152 too...

from dart_frog.

easazade avatar easazade commented on May 27, 2024 2

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.

@felangel

from dart_frog.

jakub-stefaniak avatar jakub-stefaniak commented on May 27, 2024 1

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.

felangel avatar felangel commented on May 27, 2024 1

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.

easazade avatar easazade commented on May 27, 2024 1

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.

chimon2000 avatar chimon2000 commented on May 27, 2024

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.

chimon2000 avatar chimon2000 commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.