Comments (3)
Hey @nosmirck 👋! I was interested in using protobufs as well so I played around with it and it looks totally supported by the current package with existing tools.
Basically, you can using the protoc CLI tool to generate the Dart objects for your protobuf messages, and it generates all your Dart classes.
You can then use those objects with dart_frog like this
import 'package:dart_frog/dart_frog.dart';
import 'package:protobuf_play/model.dart';
Response onRequest(RequestContext context) {
final person = Person(
id: 3,
email: '[email protected]',
name: 'Tester McTesterson',
phones: [
Person_PhoneNumber(
number: '+14068675309',
type: Person_PhoneType.HOME,
)
],
);
return Response.bytes(
body: person.writeToBuffer(),
);
}
All your generated classes also have a factory constructor called fromBuffer
which makes them super easy to convert from the Uint8List of bytes back into a useful object on the frontend side of things.
I created a little example repo showing how to use this: https://github.com/mtwichel/protobuf_play. @felangel , let me know if you want me to make a PR adding it as an example in this repo - I'd be happy to clean it up and share 💙
from dart_frog.
As discussed, closing this issue since the answer provided by @mtwichel is quite thorough and illustrates the steps needed to use protobuf in the context of a Dart Frog application.
from dart_frog.
@felangel Now that we have expanded examples, would it be okay if I merged in my protobuf example and made it a tutorial? I would also make sure it has test coverage and all that jazz.
from dart_frog.
Related Issues (20)
- 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 1
- 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
- fix: `dart_frog build` fails with "name" field doesn't match expected name HOT 1
- feat: Scheduled Tasks / Cron Jobs
- feat: add global exception catching HOT 6
- fix: Error parsing request HOT 2
- fix: zsh: command not found: dart_frog HOT 4
- chore: Release for Dart Frog CLI and Package HOT 1
- fix: When deploying to globe getting issue as: A directory corresponding to fileSystemPath "public" could not be found HOT 5
- docs: an overview document for dart_frog_cli
- fix: dart_frog dev -H HOT 1
- fix: ClientException with SocketException: Connection refused (OS Error: Connection refused, errno = 61), address = 127.0.0.1, port = 57735, uri=http://127.0.0.1:57715/status
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.