From bcdabd77f559308d902ad327d6fe104e08f3a5bd Mon Sep 17 00:00:00 2001 From: Klemen Tusar Date: Sat, 8 Feb 2025 11:12:41 +0000 Subject: [PATCH] :memo: update HTTP verb capitalization in documentation (#654) --- faq.md | 6 +++--- getting-started.md | 18 ++++++++--------- requests.md | 50 +++++++++++++++++++++++----------------------- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/faq.md b/faq.md index aaf23c00..1239e38a 100644 --- a/faq.md +++ b/faq.md @@ -67,7 +67,7 @@ Request compressRequest(Request request) { ... @FactoryConverter(request: compressRequest) -@Post() +@POST() Future postRequest(@Body() Map data); ``` @@ -131,7 +131,7 @@ abstract class ApiService extends ChopperService { return _$ApiService(client); } - @Get(path: "/get") + @GET(path: "/get") Future get(@Query() String url); } ``` @@ -487,7 +487,7 @@ abstract class TodosListService extends ChopperService { @factoryMethod static TodosListService create(ChopperClient client) => _$TodosListService(client); - @Get() + @GET() Future>> getTodos(); } ``` diff --git a/getting-started.md b/getting-started.md index 75030c20..9bb45b0e 100644 --- a/getting-started.md +++ b/getting-started.md @@ -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`, `Future>` or `Future`. 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. @@ -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 getTodos(); ``` or ```dart -@Get() +@GET() Future>> getTodos(); ``` or ```dart -@Get() +@GET() Future> getTodos(); ``` diff --git a/requests.md b/requests.md index 5a1a5703..36f63edc 100644 --- a/requests.md +++ b/requests.md @@ -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. | @@ -90,14 +90,14 @@ 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 getItemById(@Path() String id); ``` @@ -105,7 +105,7 @@ As an alternative, you can set the `@Path` annotation's `name` parameter to matc using a different parameter name, like in the following example: ```dart -@Get(path: "/{id}") +@GET(path: "/{id}") Future getItemById(@Path("id") int itemId); ``` @@ -137,7 +137,7 @@ Future search(@QueryMap() Map 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 postData(@Body() String data); ``` @@ -154,22 +154,22 @@ Request headers can be set by providing a `Map` object to the `h annotations have. ```dart -@Get(path: "/", headers: {"foo": "bar"}) +@GET(path: "/", headers: {"foo": "bar"}) Future 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 fetch(@Header("foo") String bar); +@GET(path: "/") +Future 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 @@ -184,7 +184,7 @@ We recommend annotation `@formUrlEncoded` on method that will add the correct `c into `Map` for requests. ```dart -@Post( +@POST( path: "form", ) @formUrlEncoded @@ -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}, ) @@ -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 post(@Field() String foo, @Field("b") int bar); ``` @@ -234,7 +234,7 @@ Future post(@Field() String foo, @Field("b") int bar); ### Sending a file in bytes as `List` using `@PartFile` ```dart -@Post(path: 'file') +@POST(path: 'file') @multipart Future postFile(@PartFile('file') List bytes,); ``` @@ -242,7 +242,7 @@ Future postFile(@PartFile('file') List bytes,); ### Sending a file as `MultipartFile` using `@PartFile` with extra parameters via `@Part` ```dart -@Post(path: 'file') +@POST(path: 'file') @multipart Future postMultipartFile(@PartFile() MultipartFile file, { @Part() String? id, @@ -252,7 +252,7 @@ Future postMultipartFile(@PartFile() MultipartFile file, { ### Sending multiple files as `List` using `@PartFile` ```dart -@Post(path: 'files') +@POST(path: 'files') @multipart Future postListFiles(@PartFile() List files); ``` @@ -266,15 +266,15 @@ Chopper will generate a client which will return the specified return type. When ```dart // Returns a Response -@Get(path: "/") +@GET(path: "/") Future fetch(); // Returns a Response -@Get(path: "/") +@GET(path: "/") Future> fetch(); // Returns a MyClass -@Get(path: "/") +@GET(path: "/") Future fetch(); ``` @@ -320,4 +320,4 @@ class TagConverter extends JsonConverter { } } } -``` \ No newline at end of file +```