GetMapping class

Maps HTTP GET requests to a method. On a controller, the method answers them; on a Feign client, calling the method sends one.

GET reads data without changing anything, which makes this the most common mapping. The path is optional: @GetMapping() maps the base path (the class's @RequestMapping on a controller, the @FeignClient path on a client). To give other attributes, write @GetMapping.of(path: ..., produces: ...): Dart does not allow an optional positional parameter and named ones in the same constructor.

@RestController()
@RequestMapping('/books')
class BookController {
  BookController(this.books);
  final BookService books;

  // GET /books/978-0 answers with the book as JSON.
  @GetMapping('/{isbn}')
  Future<Book> find(@PathVariable() String isbn) => books.find(isbn);

  // GET /books: the class's path itself; JSON only.
  @GetMapping.of(produces: MediaType.applicationJson)
  Future<List<Book>> all() => books.all();
}

Spring (Java):

@RestController
@RequestMapping("/books")
class BookController {
  @GetMapping("/{isbn}")
  Book find(@PathVariable String isbn) { ... }

  @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
  List<Book> all() { ... }
}
Implemented types
Annotations

Constructors

GetMapping([String path = ''])
Maps GET requests to path, relative to the base path; without a path, to the base path itself.
const
GetMapping.of({String path = '', List<String> headers = const [], String? produces, String? consumes})
Maps GET requests with every attribute by name: path, headers ('Name=value' entries), produces and consumes.
const

Properties

consumes → String?
The media types of the request body: one, or a comma-separated list.
final
hashCode → int
The hash code for this object.
no setterinherited
headers → List<String>
Header entries in Spring's syntax, such as 'X-Api-Version=2'.
final
method → HttpMethod
The HTTP method: fixed by a shortcut annotation (GET for @GetMapping), chosen freely with @RequestMapping.of.
no setteroverride
path → String
The path, relative to the base path. It may hold {variables} (/books/{isbn}), bound with @PathVariable, and ${property} placeholders, filled from the configuration at startup. A server also accepts the wildcards of PathPattern (*, **, {name:regex}).
final
produces → String?
The media types of the response: one, or a comma-separated list (MediaType.applicationJson).
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited