Skip to content

Commit

Permalink
📝 update HTTP verb capitalization in documentation (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse authored Feb 8, 2025
1 parent 79948ff commit bcdabd7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
6 changes: 3 additions & 3 deletions faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Request compressRequest(Request request) {
...
@FactoryConverter(request: compressRequest)
@Post()
@POST()
Future<Response> postRequest(@Body() Map<String, String> data);
```

Expand Down Expand Up @@ -131,7 +131,7 @@ abstract class ApiService extends ChopperService {
return _$ApiService(client);
}
@Get(path: "/get")
@GET(path: "/get")
Future<Response> get(@Query() String url);
}
```
Expand Down Expand Up @@ -487,7 +487,7 @@ abstract class TodosListService extends ChopperService {
@factoryMethod
static TodosListService create(ChopperClient client) => _$TodosListService(client);
@Get()
@GET()
Future<Response<List<Todo>>> getTodos();
}
```
18 changes: 9 additions & 9 deletions getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ The `@ChopperApi` annotation takes one optional parameter - the `baseUrl` - that

Use one of the following annotations on abstract methods of a service class to define requests:

* `@Get`
* `@GET`

* `@Post`
* `@POST`

* `@Put`
* `@PUT`

* `@Patch`
* `@PATCH`

* `@Delete`
* `@DELETE`

* `@Head`
* `@HEAD`

Request methods must return with values of the type `Future<Response>`, `Future<Response<SomeType>>` or `Future<SomeType>`.
The `Response` class is a wrapper around the HTTP response that contains the response body, the status code and the error (if any) of the request.
Expand All @@ -72,21 +72,21 @@ This class can be omitted if only the response body is needed. When omitting the
To define a `GET` request to the endpoint `/todos` in the service class above, add one of the following method declarations to the class:

```dart
@Get()
@GET()
Future<Response> getTodos();
```

or

```dart
@Get()
@GET()
Future<Response<List<Todo>>> getTodos();
```

or

```dart
@Get()
@GET()
Future<List<Todo>> getTodos();
```

Expand Down
50 changes: 25 additions & 25 deletions requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

| Annotation | HTTP verb | Description |
|--------------------------------------------|-----------|--------------------------------------------------------|
| `@Get()`, `@get` | `GET` | Defines a `GET` request. |
| `@Post()`, `@post` | `POST` | Defines a `POST` request. |
| `@Put()`, `@put` | `PUT` | Defines a `PUT` request. |
| `@Patch()`, `@patch` | `PATCH` | Defines a `PATCH` request. |
| `@Delete()`, `@delete` | `DELETE` | Defines a `DELETE` request. |
| `@Head()`, `@head` | `HEAD` | Defines a `HEAD` request. |
| `@GET()`, `@get` | `GET` | Defines a `GET` request. |
| `@POST()`, `@post` | `POST` | Defines a `POST` request. |
| `@PUT()`, `@put` | `PUT` | Defines a `PUT` request. |
| `@PATCH()`, `@patch` | `PATCH` | Defines a `PATCH` request. |
| `@DELETE()`, `@delete` | `DELETE` | Defines a `DELETE` request. |
| `@HEAD()`, `@head` | `HEAD` | Defines a `HEAD` request. |
| `@Body()`, `@body` | - | Defines the request's body. |
| `@FormUrlEncoded`, `@formUrlEncoded` | - | Defines a `application/x-www-form-urlencoded` request. |
| `@Multipart()`, `@multipart` | - | Defines a `multipart/form-data` request. |
Expand Down Expand Up @@ -90,22 +90,22 @@ Dynamic path parameters can be defined in the URL with replacement blocks. A rep
substring of the path surrounded by `{` and `}`. In the following example `{id}` is a replacement block.

```dart
@Get(path: "/{id}")
@GET(path: "/{id}")
```

Use the `@Path()` annotation to bind a parameter to a replacement block. This way the parameter's name must match a
replacement block's string.

```dart
@Get(path: "/{id}")
@GET(path: "/{id}")
Future<Response> getItemById(@Path() String id);
```

As an alternative, you can set the `@Path` annotation's `name` parameter to match a replacement block's string while
using a different parameter name, like in the following example:

```dart
@Get(path: "/{id}")
@GET(path: "/{id}")
Future<Response> getItemById(@Path("id") int itemId);
```

Expand Down Expand Up @@ -137,7 +137,7 @@ Future<Response> search(@QueryMap() Map<String, dynamic> query);
Use the `@Body` annotation on a request method parameter to specify data that will be sent as the request's body.

```dart
@Post(path: "todo/create")
@POST(path: "todo/create")
Future<Response> postData(@Body() String data);
```

Expand All @@ -154,22 +154,22 @@ Request headers can be set by providing a `Map<String, String>` object to the `h
annotations have.

```dart
@Get(path: "/", headers: {"foo": "bar"})
@GET(path: "/", headers: {"foo": "bar"})
Future<Response> fetch();
```

The `@Header` annotation can be used on method parameters to set headers dynamically for each request call.
The `@HEADer` annotation can be used on method parameters to set headers dynamically for each request call.

```dart
@Get(path: "/")
Future<Response> fetch(@Header("foo") String bar);
@GET(path: "/")
Future<Response> fetch(@HEADer("foo") String bar);
```

> Setting request headers dynamically is also supported by [Interceptors](interceptors.md)
> and [Converters](converters/converters.md).
>
> As Chopper invokes Interceptors and Converter(s) *after* creating a Request, Interceptors and Converters *can*
> override headers set with the `headers` parameter or `@Header` annotations.
> override headers set with the `headers` parameter or `@HEADer` annotations.
## Sending `application/x-www-form-urlencoded` data

Expand All @@ -184,7 +184,7 @@ We recommend annotation `@formUrlEncoded` on method that will add the correct `c
into `Map<String, String>` for requests.

```dart
@Post(
@POST(
path: "form",
)
@formUrlEncoded
Expand All @@ -208,7 +208,7 @@ To do only a single type of request with form encoding in a service, use the pro
s `requestFactory` method with the `@FactoryConverter` annotation.

```dart
@Post(
@POST(
path: "form",
headers: {contentTypeKey: formEncodedHeaders},
)
Expand All @@ -224,7 +224,7 @@ To specify fields individually, use the `@Field` annotation on method parameters
the parameter's name is used as the field's name.

```dart
@Post(path: "form")
@POST(path: "form")
@formUrlEncoded
Future<Response> post(@Field() String foo, @Field("b") int bar);
```
Expand All @@ -234,15 +234,15 @@ Future<Response> post(@Field() String foo, @Field("b") int bar);
### Sending a file in bytes as `List<int>` using `@PartFile`

```dart
@Post(path: 'file')
@POST(path: 'file')
@multipart
Future<Response> postFile(@PartFile('file') List<int> bytes,);
```

### Sending a file as `MultipartFile` using `@PartFile` with extra parameters via `@Part`

```dart
@Post(path: 'file')
@POST(path: 'file')
@multipart
Future<Response> postMultipartFile(@PartFile() MultipartFile file, {
@Part() String? id,
Expand All @@ -252,7 +252,7 @@ Future<Response> postMultipartFile(@PartFile() MultipartFile file, {
### Sending multiple files as `List<MultipartFile>` using `@PartFile`

```dart
@Post(path: 'files')
@POST(path: 'files')
@multipart
Future<Response> postListFiles(@PartFile() List<MultipartFile> files);
```
Expand All @@ -266,15 +266,15 @@ Chopper will generate a client which will return the specified return type. When

```dart
// Returns a Response<dynamic>
@Get(path: "/")
@GET(path: "/")
Future<Response> fetch();
// Returns a Response<MyClass>
@Get(path: "/")
@GET(path: "/")
Future<Response<MyClass>> fetch();
// Returns a MyClass
@Get(path: "/")
@GET(path: "/")
Future<MyClass> fetch();
```

Expand Down Expand Up @@ -320,4 +320,4 @@ class TagConverter extends JsonConverter {
}
}
}
```
```

0 comments on commit bcdabd7

Please sign in to comment.