I am back again on the track of a series of learning.
Do you know we can build a Full-stack application using Flutter only?
Yes, We can build Full stack applications with the help of the dart-frog library.
We are going to build in this series a simple Pizza-shop application.
In this part, We are going to learn about how Dart-frog basically works with static data.
What is Dart-Frog?
Dart-frog is not directly or officially related to the flutter but it is a framework designed in the dart to create a minimalist back end.
In addition, Dart Frog is intended to help Flutter/Dart developers maximize their productivity by having a unified tech stack that enables sharing tooling, models, and more!
Thanks to verygood.ventures
//📦 Install the dart_frog cli from pub.dev dart pub global activate dart_frog_cli
Creating a project
dart_frog create pizza_shop
Start the server
Note: By default 8080 port is used to change via
How do routes work?
"routes" folder contains routes for example "index.dart" is "/" home route and if we have to create another route then create a new folder in "routes" in with route_name and create a dart file named the same as the endpoint with
All route handlers have access to a RequestContext which can be used to access the incoming request as well as dependencies provided to the request context.
We can identify types of HTTP requests via
for the same, we can get also
- Query parameters:
- Json Data:
- Form Data:
Let's start working on the Pizza shop
Create models for pizzas and orders.
- Step create a new folder named
modelsand a file named
pizza_models.dartusing JSON annotation.
order_models.dartin the same folder.
Creating Endpoints for fetching the list of pizzas or specific using pizza_id.
- Before creating the endpoint, We need a List of orders and pizzas, so create a new folder in the project name
utlisand inside this create a dart file(
constant.dart) with the following content.
- create a dart file named
pizzas.dart. This method will be a GET to return a list of pizzas if no
idquery parameter is provided otherwise it will return specific pizza details.
- For fetching orders, we are going to create a GET method with the query parameter
user_idfor getting the list of orders.
- For creating an order we required the following fields
user_id,pizza_id, address, and phone number.
- Method should post only.
Will check if the headers
content type is application/JSONor not.
Will also check if the pizza_id is valid or not.
after creating the order, we will return
order-idto the user.
We are done .....................
In the next part, we are going to connect MongoDB for persisting data.
Stay Tuned .....
Top comments (4)
How to connect dart-frog with mongodb cloud?
Hi pablo sorry for late reply, you can dart-frog to Atlas using following code
var db = await Db.create("mongodb+srv://:@:/?");
and for more info
I hope it will help you.
I am having issues using JSON annotation. Would you please show how to do this?
Hi George, you can refer to this article.