+19
This commit is contained in:
parent
a72c036dd1
commit
41a73d0b20
4 changed files with 59 additions and 36 deletions
|
@ -1,6 +1,6 @@
|
||||||
# angel_client
|
# angel_client
|
||||||
|
|
||||||
[![pub 1.0.0-dev+18](https://img.shields.io/badge/pub-1.0.0--dev+18-red.svg)](https://pub.dartlang.org/packages/angel_client)
|
[![pub 1.0.0-dev+19](https://img.shields.io/badge/pub-1.0.0--dev+19-red.svg)](https://pub.dartlang.org/packages/angel_client)
|
||||||
![build status](https://travis-ci.org/angel-dart/client.svg)
|
![build status](https://travis-ci.org/angel-dart/client.svg)
|
||||||
|
|
||||||
Client library for the Angel framework.
|
Client library for the Angel framework.
|
||||||
|
|
|
@ -3,6 +3,7 @@ library angel_client;
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'package:http/src/response.dart' as http;
|
||||||
export 'package:angel_framework/src/http/angel_http_exception.dart';
|
export 'package:angel_framework/src/http/angel_http_exception.dart';
|
||||||
|
|
||||||
/// A function that configures an [Angel] client in some way.
|
/// A function that configures an [Angel] client in some way.
|
||||||
|
@ -29,6 +30,22 @@ abstract class Angel {
|
||||||
}
|
}
|
||||||
|
|
||||||
Service service<T>(Pattern path, {Type type});
|
Service service<T>(Pattern path, {Type type});
|
||||||
|
|
||||||
|
Future<http.Response> delete(String url,
|
||||||
|
{Map<String, String> headers});
|
||||||
|
|
||||||
|
Future<http.Response> get(String url, {Map<String, String> headers});
|
||||||
|
|
||||||
|
Future<http.Response> head(String url, {Map<String, String> headers});
|
||||||
|
|
||||||
|
Future<http.Response> patch(String url,
|
||||||
|
{body, Map<String, String> headers});
|
||||||
|
|
||||||
|
Future<http.Response> post(String url,
|
||||||
|
{body, Map<String, String> headers});
|
||||||
|
|
||||||
|
Future<http.Response> put(String url,
|
||||||
|
{body, Map<String, String> headers});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the result of authentication with an Angel server.
|
/// Represents the result of authentication with an Angel server.
|
||||||
|
|
|
@ -133,6 +133,46 @@ abstract class BaseAngelClient extends Angel {
|
||||||
String uri = path.replaceAll(straySlashes, "");
|
String uri = path.replaceAll(straySlashes, "");
|
||||||
return new BaseAngelService(client, this, '$basePath/$uri');
|
return new BaseAngelService(client, this, '$basePath/$uri');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _join(url) {
|
||||||
|
final head = basePath.replaceAll(new RegExp(r'/+$'), '');
|
||||||
|
final tail = basePath.replaceAll(straySlashes, '');
|
||||||
|
return '$head/$tail';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<http.Response> delete(String url,
|
||||||
|
{Map<String, String> headers}) async {
|
||||||
|
return client.delete(_join(url), headers: headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<http.Response> get(String url, {Map<String, String> headers}) async {
|
||||||
|
return client.get(_join(url), headers: headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<http.Response> head(String url, {Map<String, String> headers}) async {
|
||||||
|
return client.head(_join(url), headers: headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<http.Response> patch(String url,
|
||||||
|
{body, Map<String, String> headers}) async {
|
||||||
|
return client.patch(_join(url), body: body, headers: headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<http.Response> post(String url,
|
||||||
|
{body, Map<String, String> headers}) async {
|
||||||
|
return client.post(_join(url), body: body, headers: headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<http.Response> put(String url,
|
||||||
|
{body, Map<String, String> headers}) async {
|
||||||
|
return client.put(_join(url), body: body, headers: headers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BaseAngelService extends Service {
|
class BaseAngelService extends Service {
|
||||||
|
@ -171,12 +211,6 @@ class BaseAngelService extends Service {
|
||||||
return http.Response.fromStream(await client.send(request));
|
return http.Response.fromStream(await client.send(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
String _join(url) {
|
|
||||||
final head = basePath.replaceAll(new RegExp(r'/+$'), '');
|
|
||||||
final tail = basePath.replaceAll(straySlashes, '');
|
|
||||||
return '$head/$tail';
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<http.StreamedResponse> send(http.BaseRequest request) {
|
Future<http.StreamedResponse> send(http.BaseRequest request) {
|
||||||
if (app.authToken != null && app.authToken.isNotEmpty) {
|
if (app.authToken != null && app.authToken.isNotEmpty) {
|
||||||
request.headers['Authorization'] = 'Bearer ${app.authToken}';
|
request.headers['Authorization'] = 'Bearer ${app.authToken}';
|
||||||
|
@ -185,34 +219,6 @@ class BaseAngelService extends Service {
|
||||||
return client.send(request);
|
return client.send(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<http.Response> delete(String url,
|
|
||||||
{Map<String, String> headers}) async {
|
|
||||||
return client.delete(_join(url), headers: headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<http.Response> get(String url, {Map<String, String> headers}) async {
|
|
||||||
return client.get(_join(url), headers: headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<http.Response> head(String url, {Map<String, String> headers}) async {
|
|
||||||
return client.head(_join(url), headers: headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<http.Response> patch(String url,
|
|
||||||
{body, Map<String, String> headers}) async {
|
|
||||||
return client.patch(_join(url), body: body, headers: headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<http.Response> post(String url,
|
|
||||||
{body, Map<String, String> headers}) async {
|
|
||||||
return client.post(_join(url), body: body, headers: headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<http.Response> put(String url,
|
|
||||||
{body, Map<String, String> headers}) async {
|
|
||||||
return client.put(_join(url), body: body, headers: headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List> index([Map params]) async {
|
Future<List> index([Map params]) async {
|
||||||
final response = await sendUnstreamed(
|
final response = await sendUnstreamed(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_client
|
name: angel_client
|
||||||
version: 1.0.0-dev+18
|
version: 1.0.0-dev+19
|
||||||
description: Client library for the Angel framework.
|
description: Client library for the Angel framework.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_client
|
homepage: https://github.com/angel-dart/angel_client
|
||||||
|
|
Loading…
Reference in a new issue