GET Method
The GET method is used to send HTTP requests
of type GET
. It takes a URL
, data, and optional request parameters, returning the result of the server's processing of the request.
Properties
url: string
The URL of the resource being requested.
options: Object
An optional object containing request parameters.
Properties of the options object
-
headers:
Record<string, string | string[] | undefined>
HTTP request headers. -
searchParams:
string | Record<string, string | number | boolean | null | undefined>
Query string parameters. -
responseType:
'json' | 'text'
The type of data in the response. -
timeout:
number
The timeout for the request in milliseconds.
Return Value
Response from the server.
Response
An object representing the response from the server.
Properties of the Response object
- body:
string
The body of the response, the type is determined when the function is called.
- status:
number
HTTP status code.
- headers:
Record<string, string>
Response headers.
Example
Let's consider an example of using the GET
method in the context of retrieving a menu from an external source. A library for sending HTTP requests
is used for this purpose.
This asynchronous function sends a GET
request to the specified URL and returns the menu data.