Skip to content

Commit e1810f3

Browse files
authored
hide rest api for mobile, correct js snippets (#7446)
* hide rest api for mobile, correct js snippets * restore getStaticProps
1 parent 9038cd8 commit e1810f3

File tree

9 files changed

+61
-1625
lines changed

9 files changed

+61
-1625
lines changed

src/pages/[platform]/build-a-backend/add-aws-services/rest-api/customize-authz/index.mdx

Lines changed: 21 additions & 651 deletions
Large diffs are not rendered by default.

src/pages/[platform]/build-a-backend/add-aws-services/rest-api/delete-data/index.mdx

Lines changed: 5 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@ export const meta = {
44
title: 'Delete data',
55
description: 'Using the Delete API REST in Amplify',
66
platforms: [
7-
'javascript',
8-
'react-native',
9-
'flutter',
10-
'swift',
11-
'android',
127
'angular',
8+
'javascript',
139
'nextjs',
1410
'react',
11+
'react-native',
1512
'vue'
1613
],
1714
};
1815

19-
export const getStaticPaths = async () => {
16+
export async function getStaticPaths() {
2017
return getCustomStaticPath(meta.platforms);
21-
};
18+
}
2219

2320
export function getStaticProps(context) {
2421
return {
@@ -32,9 +29,8 @@ export function getStaticProps(context) {
3229
## DELETE requests
3330

3431
To delete an item via the API endpoint:
35-
<InlineFilter filters={['javascript', "angular", "react", "vue", "react-native", "nextjs"]}>
3632

37-
```javascript
33+
```ts
3834
import { del } from 'aws-amplify/api';
3935

4036
async function deleteItem() {
@@ -50,132 +46,3 @@ async function deleteItem() {
5046
}
5147
}
5248
```
53-
</InlineFilter>
54-
55-
<InlineFilter filters={['swift']}>
56-
57-
<BlockSwitcher>
58-
59-
<Block name="Async/Await">
60-
61-
```swift
62-
func deleteItem() async {
63-
let request = RESTRequest(path: "items")
64-
do {
65-
let data = try await Amplify.API.delete(request: request)
66-
let str = String(decoding: data, as: UTF8.self)
67-
print("Success: \(str)")
68-
} catch let error as APIError {
69-
print("Failed due to API error: ", error)
70-
} catch {
71-
print("Unexpected error: \(error)")
72-
}
73-
}
74-
```
75-
76-
</Block>
77-
78-
<Block name="Combine">
79-
80-
```swift
81-
func deleteItem() -> AnyCancellable {
82-
let request = RESTRequest(path: "items")
83-
let sink = Amplify.Publisher.create {
84-
try await Amplify.API.delete(request: request)
85-
}
86-
.sink {
87-
if case let .failure(apiError) = $0 {
88-
print("Failed", apiError)
89-
}
90-
}
91-
receiveValue: { data in
92-
let str = String(decoding: data, as: UTF8.self)
93-
print("Success \(str)")
94-
}
95-
return sink
96-
}
97-
```
98-
99-
</Block>
100-
101-
</BlockSwitcher>
102-
</InlineFilter>
103-
104-
<InlineFilter filters={['android']}>
105-
106-
<BlockSwitcher>
107-
<Block name="Java">
108-
109-
```java
110-
RestOptions options = RestOptions.builder()
111-
.addPath("/items/1")
112-
.build();
113-
114-
Amplify.API.delete(options,
115-
response -> Log.i("MyAmplifyApp", "DELETE succeeded: " + response),
116-
error -> Log.e("MyAmplifyApp", "DELETE failed.", error)
117-
);
118-
```
119-
120-
</Block>
121-
<Block name="Kotlin - Callbacks">
122-
123-
```kotlin
124-
val options = RestOptions.builder()
125-
.addPath("/items/1")
126-
.build()
127-
128-
Amplify.API.delete(options,
129-
{ Log.i("MyAmplifyApp", "DELETE succeeded: $it") },
130-
{ Log.e("MyAmplifyApp", "DELETE failed.", it) }
131-
)
132-
```
133-
134-
</Block>
135-
<Block name="Kotlin - Coroutines">
136-
137-
```kotlin
138-
val request = RestOptions.builder()
139-
.addPath("/items/1")
140-
.build()
141-
try {
142-
val response = Amplify.API.delete(request)
143-
Log.i("MyAmplifyApp", "DELETE succeeded: $response")
144-
} catch (error: ApiException) {
145-
Log.e("MyAmplifyApp", "DELETE failed", error)
146-
}
147-
```
148-
149-
</Block>
150-
<Block name="RxJava">
151-
152-
```java
153-
RestOptions options = RestOptions.builder()
154-
.addPath("/items/1")
155-
.build();
156-
157-
RxAmplify.API.delete(options)
158-
.subscribe(
159-
response -> Log.i("MyAmplifyApp", "DELETE succeeded: " + response),
160-
error -> Log.e("MyAmplifyApp", "DELETE failed.", error)
161-
);
162-
```
163-
164-
</Block>
165-
</BlockSwitcher>
166-
</InlineFilter>
167-
168-
<InlineFilter filters={['flutter']}>
169-
170-
```dart
171-
Future<void> deleteItems() async {
172-
try {
173-
final restOperation = Amplify.API.delete('items/1');
174-
final response = await restOperation.response;
175-
print('DELETE call succeeded: ${response.decodeBody()}');
176-
} on ApiException catch (e) {
177-
print('DELETE call failed: $e');
178-
}
179-
}
180-
```
181-
</InlineFilter>

src/pages/[platform]/build-a-backend/add-aws-services/rest-api/existing-resources/index.mdx

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@ export const meta = {
44
title: 'Use existing AWS resources',
55
description: 'Configure the Amplify Libraries to use existing Amazon API Gateway resources by referencing them in your configuration.',
66
platforms: [
7-
'flutter',
8-
'swift',
9-
'android',
10-
'javascript',
11-
'react-native',
127
'angular',
8+
'javascript',
139
'nextjs',
1410
'react',
11+
'react-native',
1512
'vue'
1613
],
1714
};
1815

19-
export const getStaticPaths = async () => {
16+
export async function getStaticPaths() {
2017
return getCustomStaticPath(meta.platforms);
21-
};
18+
}
2219

2320
export function getStaticProps(context) {
2421
return {
@@ -29,40 +26,9 @@ export function getStaticProps(context) {
2926
};
3027
}
3128

32-
<InlineFilter filters={['android', 'swift', 'flutter']}>
33-
Existing Amazon API Gateway resources can be used with the Amplify Libraries by referencing your API Gateway **endpoint** and configuring authorization in your `amplify_outputs.json` file.
34-
35-
```json
36-
{
37-
"api": {
38-
"plugins": {
39-
"awsAPIPlugin": {
40-
"<your-api-name>": {
41-
"endpointType": "REST",
42-
"endpoint": "<your-api-endpoint>",
43-
"region": "<your-api-region>",
44-
"authorizationType": "<your-api-authorization-type>"
45-
}
46-
}
47-
}
48-
}
49-
}
50-
```
51-
52-
- **your-api-name**: Friendly name for the API (e.g., *api*)
53-
- **endpoint**: The HTTPS endpoint of the API (e.g. *https://aaaaaaaaaa.execute-api.us-east-1.amazonaws.com/api*)
54-
- **region**: AWS Region where the resources are provisioned (e.g. *us-east-1*)
55-
- **authorizationType**: Authorization mode for accessing the API. This can be one of: `NONE`, `AWS_IAM`, `AMAZON_COGNITO_USER_POOLS`, or `API_KEY`. Each mode with the exception of `NONE` requires additional configuration parameters. See [Configure authorization modes](/[platform]/build-a-backend/add-aws-services/rest-api/customize-authz/) for details.
56-
57-
Note that before you can add an AWS resource to your application, the application must have the Amplify libraries installed. If you need to perform this step, see [Install Amplify Libraries](/[platform]/build-a-backend/add-aws-services/rest-api/set-up-rest-api/#install-amplify-libraries).
58-
59-
</InlineFilter>
60-
61-
<InlineFilter filters={['javascript','angular','nextjs','react','vue','react-native']}>
62-
6329
Existing Amazon API Gateway resources can be used with the Amplify Libraries by calling `Amplify.configure()` with the API Gateway API name and options. Note, you will need to supply the full resource configuration and library options objects when calling `Amplify.configure()`. The following example shows how to configure additional API Gateway resources to an existing Amplify application:
6430

65-
```javascript
31+
```ts
6632
import { Amplify } from 'aws-amplify';
6733
import outputs from '../amplify_outputs.json';
6834
Amplify.configure(outputs):
@@ -91,5 +57,3 @@ Amplify.configure({
9157
- **region**: AWS Region where the resources are provisioned. If not specified, the region will be inferred from the endpoint.
9258

9359
Note that before you can add an AWS resource to your application, the application must have the Amplify libraries installed. If you need to perform this step, see [Install Amplify Libraries](/[platform]/build-a-backend/add-aws-services/rest-api/set-up-rest-api/#install-amplify-libraries).
94-
95-
</InlineFilter>

0 commit comments

Comments
 (0)