teja_http_json 0.1.5

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 73

teja_http_json

Write concise JSON API clients

Usage

Get request

final JsonResponse resp =
    await client.get('http://localhost:8080/api/list');
print(resp.body);

Post request

final JsonResponse resp = await client
    .post('http://localhost:8080/api/map', body: {'posting': 'hello'});
print(resp.body);

Put request

final JsonResponse resp = await client
    .put('http://localhost:8080/api/map', body: {'putting': 'hello'});
print(resp.body);

Delete request

final JsonResponse resp =
    await client.delete('http://localhost:8080/api/map/123?query=why');
print(resp.body);

Changelog

0.1.2

  • Serialize/Deserialize using jaguar_serializer

0.0.1

  • Initial version

example/teja_http_json_example.dart

// Copyright (c) 2017, teja. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'dart:io';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'package:jaguar/jaguar.dart';
import 'package:jaguar_reflect/jaguar_reflect.dart';
import 'package:teja_http_json/teja_http_json.dart';

@Api(path: '/api')
class ExampleApi {
  @Get(path: '/map')
  Response<String> getMap(Context ctx) => Response.json({
        'jaguar': 'awesome',
      });

  @Get(path: '/list')
  Response<String> getList(Context ctx) => Response.json(['Hello', 'World']);

  @Get(path: '/string')
  Response<String> getString(Context ctx) => Response.json("Jaguar");

  @Get(path: '/header')
  Response<String> getHeader(Context ctx) =>
      Response.json({'testing': ctx.req.headers.value('jaguar-testing')});

  @Post(path: '/map')
  Future<Response<String>> postMap(Context ctx) async =>
      Response.json(await ctx.req.bodyAsJsonMap());

  @Put(path: '/map')
  Future<Response<String>> putMap(Context ctx) async =>
      Response.json(await ctx.req.bodyAsJsonMap());

  @Delete(path: '/map/:id')
  Response<String> deleteMap(Context ctx) =>
      Response.json({'id': ctx.pathParams.id, 'query': ctx.queryParams.query});
}

Future serve() async {
  Jaguar server = new Jaguar();
  server.addApi(reflectJaguar(new ExampleApi()));
  await server.serve();
}

Future client() async {
  final http.Client baseClient = new http.Client();
  final JsonClient client = new JsonClient(baseClient);

  {
    final JsonResponse resp = await client.get('http://localhost:8080/api/map');
    print(resp.body);
  }

  {
    final JsonResponse resp =
        await client.get('http://localhost:8080/api/list');
    print(resp.body);
  }

  {
    final JsonResponse resp =
        await client.get('http://localhost:8080/api/string');
    print(resp.body);
  }

  {
    final JsonResponse resp = await client.get(
        'http://localhost:8080/api/header',
        headers: {'jaguar-testing': 'testing 1 2 3'});
    print(resp.body);
  }

  {
    final JsonResponse resp = await client
        .post('http://localhost:8080/api/map', body: {'posting': 'hello'});
    print(resp.body);
  }

  {
    final JsonResponse resp = await client
        .put('http://localhost:8080/api/map', body: {'putting': 'hello'});
    print(resp.body);
  }

  {
    final JsonResponse resp =
        await client.delete('http://localhost:8080/api/map/123?query=why');
    print(resp.body);
  }
}

main() async {
  await serve();
  await client();

  exit(0);
}

1. Depend on it

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


dependencies:
  teja_http_json: "^0.1.5"

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 packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:teja_http_json/teja_http_json.dart';
        
Version Uploaded Documentation Archive
0.1.5 Jul 9, 2017 Go to the documentation of teja_http_json 0.1.5 Download teja_http_json 0.1.5 archive
0.1.4 Jul 8, 2017 Go to the documentation of teja_http_json 0.1.4 Download teja_http_json 0.1.4 archive
0.1.3 Jul 7, 2017 Go to the documentation of teja_http_json 0.1.3 Download teja_http_json 0.1.3 archive
0.1.2 Jul 7, 2017 Go to the documentation of teja_http_json 0.1.2 Download teja_http_json 0.1.2 archive
0.1.1 Jul 3, 2017 Go to the documentation of teja_http_json 0.1.1 Download teja_http_json 0.1.1 archive
0.1.0 Jun 18, 2017 Go to the documentation of teja_http_json 0.1.0 Download teja_http_json 0.1.0 archive
0.0.1 Feb 21, 2017 Go to the documentation of teja_http_json 0.0.1 Download teja_http_json 0.0.1 archive
0.1.6-dev Jul 13, 2017 Go to the documentation of teja_http_json 0.1.6-dev Download teja_http_json 0.1.6-dev archive

Analysis

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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

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

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:teja_http_json/teja_http_json.dart.

Suggestions

  • Fix analysis_options.yaml.

    We were unable to parse analysis_options.yaml.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 6 hints.

    Run dartfmt to format lib/src/response.dart.

    Run dartfmt to format lib/src/teja_http_json.dart.

  • Enable strong mode analysis.

    Strong mode helps you to detect bugs and potential issues earlier.Start your analysis_options.yaml file with the following:

    analyzer:
      strong-mode: true
    

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <2.0.0
http >=0.11.3 <0.12.0 0.11.3+16
jaguar_serializer >=0.3.10 <0.4.0 0.3.16 0.5.1
Transitive dependencies
analyzer 0.30.0+4 0.31.1
args 1.4.2
async 1.13.3 2.0.6
barback 0.15.2+15
build 0.9.3 0.12.2
build_barback 0.3.0 0.5.0+3
build_runner 0.3.4+1 0.8.3
charcode 1.1.1
cli_util 0.1.2+1
code_transformers 0.5.1+4
collection 1.14.9
convert 2.0.1
crypto 2.0.2+1
csslib 0.14.1
dart_style 1.0.9+1 1.0.10
front_end 0.1.0-alpha.4.1 0.1.0-alpha.11
glob 1.1.5
html 0.13.3
http_parser 3.1.1
intl 0.14.0 0.15.6
isolate 1.1.0 2.0.0
jaguar_generator_config 0.0.1
kernel 0.3.0-alpha.1.1 0.3.0-alpha.11
logging 0.11.3+1
meta 1.1.2
mime 0.9.6
package_config 1.0.3
path 1.5.1
plugin 0.2.0+2
pool 1.3.4
quiver_iterables 1.0.1
shelf 0.6.8 0.7.2
shelf_static 0.2.7
source_gen 0.5.10+1 0.8.1
source_gen_help 0.0.4
source_maps 0.10.4
source_span 1.4.0
stack_trace 1.9.2
stream_channel 1.6.5
stream_transform 0.0.11
string_scanner 1.0.2
typed_data 1.1.5
utf 0.9.0+4
watcher 0.9.7+7
yaml 2.1.13
yamlicious 0.0.5
Dev dependencies
jaguar >=0.5.8 <0.6.0
jaguar_reflect >=0.5.1 <0.6.0
test >=0.12.19+1 <0.13.0