alice 0.0.5 copy "alice: ^0.0.5" to clipboard
alice: ^0.0.5 copied to clipboard

outdated

Alice is an HTTP Inspector tool which helps debugging http requests. It catches and stores http requests and responses, which can be viewed via simple UI.

example/lib/main.dart

import 'dart:convert';
import 'dart:io';
import 'package:alice/alice.dart';
import 'package:http/http.dart' as http;

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Alice alice;
  Dio dio;
  HttpClient httpClient;

  @override
  void initState() {
    alice = Alice(showNotification: true);
    dio = Dio();
    dio.interceptors.add(alice.getDioInterceptor());
    httpClient = HttpClient();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: alice.getNavigatorKey(),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Alice HTTP Inspector example'),
        ),
        body: Center(
            child:
                Column(mainAxisAlignment: MainAxisAlignment.center, children: [
          RaisedButton(
            child: Text("Run HTTP Requests"),
            onPressed: _runHttpRequests,
          ),
          RaisedButton(
            child: Text("Run HTTP Insepctor"),
            onPressed: _runHttpInspector,
          )
        ])),
      ),
    );
  }

  void _runHttpRequests() async {
    Map<String, dynamic> body = {"title": "foo", "body": "bar", "userId": "1"};
    http
        .post('https://jsonplaceholder.typicode.com/posts', body: body)
        .then((response) {
      alice.onHttpResponse(response, body: body);
    });

    http.get('https://jsonplaceholder.typicode.com/posts').then((response) {
      alice.onHttpResponse(response);
    });

    http
        .put('https://jsonplaceholder.typicode.com/posts/1', body: body)
        .then((response) {
      alice.onHttpResponse(response, body: body);
    });

    http
        .patch('https://jsonplaceholder.typicode.com/posts/1', body: body)
        .then((response) {
      alice.onHttpResponse(response, body: body);
    });

    http
        .delete('https://jsonplaceholder.typicode.com/posts/1')
        .then((response) {
      alice.onHttpResponse(response);
    });

    http.get('https://jsonplaceholder.typicode.com/test/test').then((response) {
      alice.onHttpResponse(response);
    });

    httpClient
        .postUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts"))
        .then((request) async {
      alice.onHttpClientRequest(request, body: body);
      request.write(body);
      var httpResponse = await request.close();
      var responseBody = await httpResponse.transform(utf8.decoder).join();
      alice.onHttpClientResponse(httpResponse, request, body: responseBody);
    });

    httpClient
        .getUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts"))
        .then((request) async {
      alice.onHttpClientRequest(request);
      var httpResponse = await request.close();
      var responseBody = await httpResponse.transform(utf8.decoder).join();
      alice.onHttpClientResponse(httpResponse, request, body: responseBody);
    });

    httpClient
        .putUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts/1"))
        .then((request) async {
      alice.onHttpClientRequest(request, body: body);
      request.write(body);
      var httpResponse = await request.close();
      var responseBody = await httpResponse.transform(utf8.decoder).join();
      alice.onHttpClientResponse(httpResponse, request, body: responseBody);
    });

    httpClient
        .patchUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts/1"))
        .then((request) async {
      alice.onHttpClientRequest(request, body: body);
      request.write(body);
      var httpResponse = await request.close();
      var responseBody = await httpResponse.transform(utf8.decoder).join();
      alice.onHttpClientResponse(httpResponse, request, body: responseBody);
    });

    httpClient
        .deleteUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts/1"))
        .then((request) async {
      alice.onHttpClientRequest(request);
      var httpResponse = await request.close();
      var responseBody = await httpResponse.transform(utf8.decoder).join();
      alice.onHttpClientResponse(httpResponse, request, body: responseBody);
    });

    httpClient
        .getUrl(Uri.parse("https://jsonplaceholder.typicode.com/test/test/"))
        .then((request) async {
      alice.onHttpClientRequest(request);
      var httpResponse = await request.close();
      var responseBody = await httpResponse.transform(utf8.decoder).join();
      alice.onHttpClientResponse(httpResponse, request, body: responseBody);
    });

    dio.post("https://jsonplaceholder.typicode.com/posts", data: body);
    dio.get("https://jsonplaceholder.typicode.com/posts");
    dio.put("https://jsonplaceholder.typicode.com/posts/1", data: body);
    dio.put("https://jsonplaceholder.typicode.com/posts/1", data: body);
    dio.delete("https://jsonplaceholder.typicode.com/posts/1");
    dio.get("https://jsonplaceholder.typicode.com/test/test");
  }

  void _runHttpInspector() {
    alice.showInspector();
  }
}
268
likes
0
pub points
97%
popularity

Publisher

unverified uploader

Alice is an HTTP Inspector tool which helps debugging http requests. It catches and stores http requests and responses, which can be viewed via simple UI.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

dio, flutter, flutter_local_notifications, http, rxdart

More

Packages that depend on alice