jaguar_example_json 2.1.2

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 0

json

Examples to demonstrate how to implement JSON routes using Jaguar web framework.

Parsing JSON request

Context object provides bodyAsJson, bodyAsJsonMap and bodyAsJsonList methods to deserialize JSON requests into built-in Dart objects. convert parameters of bodyAsJson and bodyAsJsonList can be further used to convert built-in Dart object into desired Dart object.

  server.post('/addition', (Context ctx) async {
    AddInput input = await ctx.bodyAsJson(convert: AddInput.fromMap);
    return input.a + input.b;
  });

Writing JSON response

JSON variants of HTTP methods like getJson, postJson, putJson and deleteJson automatically serializes the returned result into JSON.

  server.postJson('/all', (Context ctx) async {
    AddInput inp = await ctx.bodyAsJson(convert: AddInput.fromMap);
    return AllResults(addition: inp.a + inp.b, subtraction: inp.a - inp.b);
  });

In Controllers use GetJson, PostJson, DeleteJson and PutJson annotations instead.

Client

The example also includes a client to test run the server.

$> dart bin/client.dart
25
{addition: 25, subtraction: 5}

Postman collection

The example also includes a Postman collection to test run the server.

Postman

Changelog

2.1.1

  • Architecture

Use this package as a library

1. Depend on it

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


dependencies:
  jaguar_example_json: ^2.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

Version Uploaded Documentation Archive
2.1.2 Jul 10, 2018 Go to the documentation of jaguar_example_json 2.1.2 Download jaguar_example_json 2.1.2 archive
2.1.1 Jul 10, 2018 Go to the documentation of jaguar_example_json 2.1.1 Download jaguar_example_json 2.1.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.55.0 <2.0.0