Skip to content

Commit

Permalink
Merge pull request #20 from ricardoboss/issues/19-http-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoboss authored Apr 8, 2024
2 parents 49e6de5 + 6a2c487 commit 192b681
Show file tree
Hide file tree
Showing 22 changed files with 531 additions and 30 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ jobs:
run: dart format --output=none --set-exit-if-changed .
working-directory: packages/${{ matrix.package }}

- name: Run build_runner
if: contains(fromJson('[ "kiota_abstractions", "kiota_http" ]'), matrix.package)
run: dart run build_runner build --delete-conflicting-outputs
working-directory: packages/${{ matrix.package }}

- name: Analyze project source
continue-on-error: true
run: dart analyze --fatal-infos
working-directory: packages/${{ matrix.package }}

- name: Run build_runner
if: contains(fromJson('[ "kiota_abstractions" ]'), matrix.package)
run: dart run build_runner build --delete-conflicting-outputs
working-directory: packages/${{ matrix.package }}

- name: Run tests
run: dart test
working-directory: packages/${{ matrix.package }}
7 changes: 7 additions & 0 deletions .run/All Tests.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="All Tests" type="CompoundRunConfigurationType">
<toRun name="Test kiota_abstractions" type="DartTestRunConfigurationType" />
<toRun name="Test kiota_http" type="DartTestRunConfigurationType" />
<method v="2" />
</configuration>
</component>
7 changes: 7 additions & 0 deletions .run/Test kiota_abstractions.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test kiota_abstractions" type="DartTestRunConfigurationType" factoryName="Dart Test">
<option name="filePath" value="$PROJECT_DIR$/packages/kiota_abstractions/test" />
<option name="scope" value="FOLDER" />
<method v="2" />
</configuration>
</component>
7 changes: 7 additions & 0 deletions .run/Test kiota_http.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test kiota_http" type="DartTestRunConfigurationType" factoryName="Dart Test">
<option name="filePath" value="$PROJECT_DIR$/packages/kiota_http/test" />
<option name="scope" value="FOLDER" />
<method v="2" />
</configuration>
</component>
17 changes: 17 additions & 0 deletions .run/watch kiota_abstractions.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="watch kiota_abstractions" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="dart run build_runner watch" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/packages/kiota_abstractions/" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="build_runner watch" type="ShConfigurationType">
<configuration default="false" name="watch kiota_http" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="dart run build_runner watch" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/packages/kiota_http/" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
Expand Down
1 change: 1 addition & 0 deletions packages/kiota_abstractions/lib/kiota_abstractions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:std_uritemplate/std_uritemplate.dart';
import 'package:uuid/uuid.dart';

part 'src/api_client_builder.dart';
part 'src/api_exception.dart';
part 'src/authentication/access_token_provider.dart';
part 'src/authentication/allowed_hosts_validator.dart';
part 'src/authentication/anonymous_authentication_provider.dart';
Expand Down
21 changes: 20 additions & 1 deletion packages/kiota_abstractions/lib/src/api_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ApiException implements Exception {
this.statusCode,
this.message,
this.responseHeaders,
this.innerExceptions,
});

/// The HTTP status code of the response.
Expand All @@ -19,8 +20,26 @@ class ApiException implements Exception {
/// The headers of the response.
final Map<String, List<String>>? responseHeaders;

/// The inner exceptions that caused this exception.
final Iterable<Object?>? innerExceptions;

@override
String toString() {
return 'ApiException{statusCode: $statusCode, message: $message, headers: $responseHeaders}';
return 'ApiException{statusCode: $statusCode, message: $message, headers: $responseHeaders, innerExceptions: $innerExceptions}';
}

/// Creates a new instance of [ApiException] with the given parameters.
ApiException copyWith({
int? statusCode,
String? message,
Map<String, List<String>>? responseHeaders,
Iterable<Object?>? innerExceptions,
}) {
return ApiException(
statusCode: statusCode ?? this.statusCode,
message: message ?? this.message,
responseHeaders: responseHeaders ?? this.responseHeaders,
innerExceptions: innerExceptions ?? this.innerExceptions,
);
}
}
23 changes: 14 additions & 9 deletions packages/kiota_abstractions/lib/src/http_method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@ part of '../kiota_abstractions.dart';
/// Represents the HTTP method used by a request.
enum HttpMethod {
/// The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.
get,
get('GET'),

/// The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.
post,
post('POST'),

/// The PATCH method is used to apply partial modifications to a resource.
patch,
patch('PATCH'),

/// The DELETE method deletes the specified resource.
delete,
delete('DELETE'),

/// The OPTIONS method is used to describe the communication options for the target resource.
options,
options('OPTIONS'),

/// The PUT method replaces all current representations of the target resource with the request payload.
put,
put('PUT'),

/// The HEAD method asks for a response identical to that of a GET request, but without the response body.
head,
head('HEAD'),

/// The CONNECT method establishes a tunnel to the server identified by the target resource.
connect,
connect('CONNECT'),

/// The TRACE method performs a message loop-back test along the path to the target resource.
trace,
trace('TRACE');

const HttpMethod(this.value);

/// The value or name of the method (for example "GET" or "POST").
final String value;
}
4 changes: 4 additions & 0 deletions packages/kiota_abstractions/lib/src/request_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ abstract class RequestAdapter {
/// the implementing adapter.
/// [T] is the type of the native request.
Future<T?> convertToNativeRequest<T>(RequestInformation requestInfo);

/// Enables the backing store proxies for the [SerializationWriter]s and
/// [ParseNode]s in use using the given [backingStoreFactory].
void enableBackingStore(BackingStoreFactory backingStoreFactory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RequestInformation {
HttpHeaders get headers => _headers;

/// The request body.
Uint8List content = Uint8List(0);
Uint8List? content;

final Map<String, RequestOption> _requestOptions = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ void main() {
expect(blank.pathParameters, <String, dynamic>{});
expect(blank.queryParameters, <String, dynamic>{});
expect(blank.headers, HttpHeaders());
expect(
blank.content,
isA<Uint8List>()
.having((content) => content.length, 'length', equals(0)),
);
expect(blank.content, isNull);
expect(blank.requestOptions, <RequestOption>[]);

expect(() => blank.uri, throwsArgumentError);
Expand Down
9 changes: 9 additions & 0 deletions packages/kiota_http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ Install the package in the generated project:
```bash
dart pub add kiota_http
```
## Development
To build the package, you first need to run `build_runner`.
It generates the necessary files for the package to work and for running the tests:
```bash
dart run build_runner build -d
```
1 change: 1 addition & 0 deletions packages/kiota_http/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:strict/analysis_options.yaml
6 changes: 6 additions & 0 deletions packages/kiota_http/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
targets:
$default:
builders:
build_version:
options:
output: lib/gen/version.dart
15 changes: 15 additions & 0 deletions packages/kiota_http/lib/kiota_http.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// This library implements a request adapter for generated
/// [Kiota](https://github.com/microsoft/kiota) clients.
library kiota_http;

import 'dart:typed_data';

import 'package:http/http.dart' as http;
import 'package:http/retry.dart' as retry;
import 'package:kiota_abstractions/kiota_abstractions.dart';
import 'package:kiota_http/gen/version.dart';
import 'package:uuid/uuid.dart';

part 'src/http_client_request_adapter.dart';
part 'src/kiota_client_factory.dart';
part 'src/middleware/user_agent_client.dart';
Loading

0 comments on commit 192b681

Please sign in to comment.