jaguar_example_json 2.1.2

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • new50

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

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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

Analysis

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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
50
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Suggestions

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use jaguar_example_json.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.55.0 <2.0.0
http ^0.11.3 0.11.3+17
jaguar ^2.1.8 2.1.25
jaguar_resty ^2.5.5 2.5.16
Transitive dependencies
async 2.0.7
auth_header 0.0.3
charcode 1.1.2
client_cookie 2.1.2
collection 1.14.10
convert 2.0.1
crypto 2.0.5
http_parser 3.1.2
http_server 0.9.8
jaguar_common 0.2.2
logging 0.11.3+1
mime 0.9.6+1
path 1.6.1
source_span 1.4.0
stack_trace 1.9.2
string_scanner 1.0.2
typed_data 1.1.5