'How does the dio package in flutter joins the base-url with url and apikey
How does the dio package in flutter joins the base-url with url and apikey in this code. Iam bit confused with the working of dio package can somebody please help me
If I have a URL of this kind
const req = unirest("GET", "https://tasty.p.rapidapi.com/recipes/list");
"X-RapidAPI-Host": "tasty.p.rapidapi.com",
"X-RapidAPI-Key": "f2c5e7c653mshbc6a7a174c0cda1p1d46c4jsna9d84f0c1681",
"useQueryString": true
Solution 1:[1]
Here is an example of making HTTP requests using DIO package:
class Api {
BaseOptions options = BaseOptions(
baseUrl: "your_base_url",
connectTimeout: 30 * 1000,
receiveTimeout: 30 * 1000,
headers: {
'Content-Type': 'application/json',
'X-RapidAPI-Host': 'tasty.p.rapidapi.com',
'X-RapidAPI-Key': '....',
'useQueryString': true
},
);
Dio getDio() {
return Dio(options);
}
Future<dynamic> getRequest(Map<String, String> params) async {
var result;
params['query'] = 'abc'
try {
Dio dio = getDio();
result = await dio.get('/url-path', queryParameters: params);
} on DioError catch (e) {
print(e.toString());
}
if (result != null) {
return result;
}
return null;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Md. Kamrul Amin |
