teja_http_json 0.1.5

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

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

This feature is new.
We welcome feedback.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Dec 6, 2017
  • Dart: 2.0.0-dev.8.0
  • pana: 0.7.3+1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
13
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
98
Overall score:
Weighted score of the above. [more]
55

Platforms

Detected platforms: Flutter, server, web

All libraries agree

Suggestions

  • Fix analysis_options.yaml.

    We were unable to parse analysis_options.yaml.

  • 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
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.0-alpha.2
args 1.2.0
async 1.13.3 2.0.1
barback 0.15.2+13
build 0.9.3 0.11.1
build_barback 0.3.0 0.4.0+2
build_runner 0.3.4+1 0.6.1
charcode 1.1.1
cli_util 0.1.2+1
code_transformers 0.5.1+3
collection 1.14.3
convert 2.0.1
crypto 2.0.2+1
csslib 0.14.1
dart_style 1.0.8
front_end 0.1.0-alpha.4.1 0.1.0-alpha.7
glob 1.1.5
html 0.13.2
http_parser 3.1.1
intl 0.14.0 0.15.2
isolate 1.1.0
jaguar_generator_config 0.0.1
kernel 0.3.0-alpha.1.1 0.3.0-alpha.4
logging 0.11.3+1
meta 1.1.2
mime 0.9.4
package_config 1.0.3
path 1.5.1
plugin 0.2.0+2
pool 1.3.3
quiver_iterables 1.0.1
shelf 0.6.8 0.7.1
shelf_static 0.2.6
source_gen 0.5.10+1 0.7.2+1
source_gen_help 0.0.4
source_maps 0.10.4
source_span 1.4.0
stack_trace 1.9.1
stream_channel 1.6.2
stream_transform 0.0.9
string_scanner 1.0.2
typed_data 1.1.5
utf 0.9.0+3
watcher 0.9.7+4
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