dartion 0.0.7

  • Readme
  • Changelog
  • Installing
  • 47

Dartion #

Dartion is a RESTful mini web server based on JSON. This is not just a port of the popular json-server for Dart as it adds other features like JWT Authentication.

Goal #

Get your backend up in 5 seconds! This will make it easier for those who take front-end video classes like Flutter and need a server. From here, just populate the json file and you will have a simple and ready to use database.

Installation #

  1. Get the Dart SDK:


  1. Activate Dartion using pub:
 pub global activate dartion

Commands #


Updates Dartion's version:

dartion upgrade

Init server:

Execute this command in an empty folder:

dartion init

This will create some configuration files for the quick operation of the server.

Start server:

This command will boot the server based on the settings in config.yaml.

dartion serve

Route system #

When running Dartion, we have a structure based on RESTful while the data persists in a JSON file in the folder.

GET    /products     -> Get all products
GET    /products/1   -> Get one product
POST   /products     -> Add more one product
PUT    /products/1   -> Edit one product
PATCH  /products/1   -> Edit one product
DELETE /products/1   -> Delete one product

POST, PUT and PATH requests must have body as JSON. It is not necessary to pass the ID as it is always auto incremented.

File Upload #

You can configure Dartion to accept upload files such as images, pdf's, etc... Adds storage properties to config.yaml

  name: "file"
  folder: storage/

File uploads work with "Multipart-form", so you can use the name property to name your upload. We can choose which folder the uploaded files will be on the server using the folder property. Then you will have two reserved routes, one to upload files and the other to retrieve those binaries.

POST /storage               -> Send files in Multipart-form
GET  /file/:your-file.ext   -> Retrieve file 

NOTE: The /storage route returns the file name.

Authetication #

You can use JWT Authentication in two steps.

  1. Use the auth property in your config.yaml
name: Test
port: 3031
db: db.json
statics: public/

  key: dajdi3cdj8jw40jv89cj4uybfg9wh9vcnvb
  exp: 3600
    - animals
    - cities

That's enough to protect your routes. The auth property takes some configuration parameters:

key -> To sign your token
exp -> Token expiration time in seconds
scape -> List of routes that will not be affected by token protection
  1. Login using the /auth route:

To retrieve the token you need a credential. A credential is basically base64(email:password)

See an example in Dart:

String email = "jose@gmail.com";
String password = "123";
String info = "$email:$password";
String encode = base64Encode(info.codeUnits);

String credencials = "Basic $encode";

You can now make a GET request to /auth, passing the credentials in the authorization header.

exemple in dart

// Using the package http

Response response = await http.get(
  headers: {'authorization': credencials},

This will return the token and some user information.

  "user": {
    "name": "Jose",
    "email": "jose@gmail.com"
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODc5NjQ1MTAsImlhdCI6MTU4Nzk2MDkxMCwiaXNzIjoiZGFydGlvIiwic3ViIjoibnVsbCJ9.5AeEIpYeu04fKINg6e8Ic5fpT0-KyZH8yPLOO6HoLVA",
  "exp": 3600

That's it! Now, just use the token to access the routes:

Response response = await http.get(
  headers: {'authorization': "Bearer $token"},

NOTE: When using Authentication, you will need to have a users property in your db.json with a user list containing at least email and password in order to access.

Community #

For more details, join our Telegram Group Flutterando

0.0.7 - 27 Apr 2020 #

  • Added File upload (check documentation)

0.0.4 - 27 Apr 2020 #

  • Initial version

Use this package as an executable

1. Install it

You can install the package from the command line:

$ pub global activate dartion

2. Use it

The package has the following executables:

$ dartion

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  dartion: ^0.0.7

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:dartion/dartion.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15

Analysis suggestions

Package not compatible with runtime flutter-web on Web


  • package:dartion/dartion.dart that imports:
  • package:dartion/src/server/dartio_server.dart that imports:
  • package:dartion/src/config/config_model.dart that imports:
  • package:dartion/src/config/database.dart that imports:
  • dart:io

Package not compatible with runtime js


  • package:dartion/dartion.dart that imports:
  • package:dartion/src/server/dartio_server.dart that imports:
  • package:dartion/src/config/config_model.dart that imports:
  • package:dartion/src/config/database.dart that imports:
  • dart:io

Health issues and suggestions

Document public APIs. (-1 points)

35 out of 35 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix bin/main.dart. (-1 points)

Analysis of bin/main.dart reported 2 hints:

line 3 col 8: Avoid relative imports for files in lib/.

line 4 col 8: Avoid relative imports for files in lib/.

Fix lib/src/server/dartio_server.dart. (-0.50 points)

Analysis of lib/src/server/dartio_server.dart reported 1 hint:

line 135 col 7: Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and dartion.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
http_server ^0.9.8+3 0.9.8+3
jaguar_jwt ^2.1.6 2.1.6
path ^1.7.0 1.7.0
yaml ^2.2.0 2.2.1
Transitive dependencies
auth_header 2.1.4
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
crypto 2.1.5
meta 1.2.2 1.3.0-nullsafety
mime 0.9.6+3
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety
Dev dependencies
pedantic ^1.8.0
test ^1.6.0