Skip to content

Commit

Permalink
chore: fix code snippets in rest api section
Browse files Browse the repository at this point in the history
  • Loading branch information
khatruong2009 committed May 7, 2024
1 parent e271b64 commit ecf201e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/fragments/lib-v1/graphqlapi/flutter/authz/20_oidc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class CustomOIDCProvider extends OIDCAuthProvider {
}
```

import warning from "/src/fragments/lib/graphqlapi/flutter/authz/2X_add_plugin.mdx";
import warning from "/src/fragments/lib-v1/graphqlapi/flutter/authz/2X_add_plugin.mdx";

<Fragments fragments={{flutter: warning}} />
18 changes: 8 additions & 10 deletions src/fragments/lib-v1/restapi/flutter/delete.mdx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
## DELETE requests

```dart
Future<void> deleteTodo() async {
try {
const options = RestOptions(path: '/todo/1');
final restOperation = Amplify.API.delete(restOptions: options);
final response = await restOperation.response;
print('DELETE call succeeded');
print(response.body);
} on ApiException catch (e) {
print('DELETE call failed: $e');
}
Future<void> deleteTodo() async {
try {
final restOperation = Amplify.API.delete('todo/1');
final response = await restOperation.response;
print('DELETE call succeeded: ${response.decodeBody()}');
} on ApiException catch (e) {
print('DELETE call failed: $e');
}
}
```


Expand Down
17 changes: 7 additions & 10 deletions src/fragments/lib-v1/restapi/flutter/fetch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ To make a GET request use `Amplify.API.get`:
```dart
Future<void> getTodo() async {
try {
const options = RestOptions(path: '/todo');
final restOperation = Amplify.API.get(restOptions: options);
final restOperation = Amplify.API.get('todo');
final response = await restOperation.response;
print('GET call succeeded: ${response.body}');
print('GET call succeeded: ${response.decodeBody()}');
} on ApiException catch (e) {
print('GET call failed: $e');
print('GET call failed: $e');
}
}
```
Expand Down Expand Up @@ -56,14 +55,12 @@ Then you can use query parameters in your path as follows:
```dart
Future<void> getTodo() async {
try {
const options = RestOptions(
path: '/todo',
queryParameters: {'q' : 'test'},
final restOperation = Amplify.API.get(
'todo',
queryParameters: {'q': 'test'},
);
final restOperation = Amplify.API.get(restOptions: options);
final response = await restOperation.response;
print('GET call succeeded');
print(response.body);
print('GET call succeeded: ${response.decodeBody()}');
} on ApiException catch (e) {
print('GET call failed: $e');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Add the following dependencies to your `pubspec.yaml` file and install dependenc

```yaml
environment:
sdk: ">=2.15.0 <3.0.0"
sdk: ">=2.18.0 <4.0.0"

dependencies:
flutter:
sdk: flutter
amplify_flutter: ^0.6.0
amplify_api: ^0.6.0
amplify_auth_cognito: ^0.6.0
amplify_flutter: ^1.0.0
amplify_api: ^1.0.0
amplify_auth_cognito: ^1.0.0
```
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
```dart
import 'dart:typed_data';
Future<void> postTodo() async {
try {
final options = RestOptions(
path: '/todo',
body: Uint8List.fromList('{\'name\':\'Mow the lawn\'}'.codeUnits)
);
final restOperation = Amplify.API.post(
restOptions: options
'todo',
body: HttpPayload.json({'name': 'Mow the lawn'}),
);
final response = await restOperation.response;
print('POST call succeeded');
print(response.body);
print(response.decodeBody());
} on ApiException catch (e) {
print('POST call failed: $e');
}
}
```
```
11 changes: 5 additions & 6 deletions src/fragments/lib-v1/restapi/flutter/update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ To update an item via the API endpoint:
```dart
Future<void> updateTodo() async {
try {
final options = RestOptions(
path: '/todo/1',
body: Uint8List.fromList('{\'name\':\'Mow the lawn\'}'.codeUnits),
final restOperation = Amplify.API.put(
'todo/1',
body: HttpPayload.json({'name': 'Mow the lawn'}),
);
final restOperation = Amplify.API.put(restOptions: options);
final response = await restOperation.response;
print('PUT call succeeded');
print(response.body);
print(response.decodeBody());
} on ApiException catch (e) {
print('PUT call failed: $e');
}
}
```
```

0 comments on commit ecf201e

Please sign in to comment.