Skip to content

Commit f0f3a57

Browse files
committed
Updating README
1 parent 0e34d3d commit f0f3a57

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# http_interceptor
22

3-
A middleware library that lets you modify requests and responses if desired. Based of on (http_middleware)[https://github.com/TEDConsulting/http_middleware]
3+
A middleware library that lets you modify requests and responses if desired. Based of on [http_middleware](https://github.com/TEDConsulting/http_middleware)
44

55
## Getting Started
66

@@ -52,8 +52,8 @@ class WeatherApiInterceptor implements InterceptorContract {
5252
@override
5353
Future<RequestData> interceptRequest({RequestData data}) async {
5454
try {
55-
data.url = "${data.url}&appid=$OPEN_WEATHER_API_KEY";
56-
data.url = "${data.url}&units=metric";
55+
data.params['appid'] = OPEN_WEATHER_API_KEY;
56+
data.params['units'] = 'metric';
5757
data.headers["Content-Type"] = "application/json";
5858
} catch (e) {
5959
print(e);
@@ -85,7 +85,8 @@ class WeatherRepository {
8585
Future<Map<String, dynamic>> fetchCityWeather(int id) async {
8686
var parsedWeather;
8787
try {
88-
final response = await client.get("$baseUrl/weather?id=$id");
88+
final response =
89+
await client.get("$baseUrl/weather", params: {'id': "$id"});
8990
if (response.statusCode == 200) {
9091
parsedWeather = json.decode(response.body);
9192
} else {
@@ -111,13 +112,11 @@ class WeatherRepository {
111112
112113
113114
Future<Map<String, dynamic>> fetchCityWeather(int id) async {
114-
HttpWithInterceptor http = HttpWithInterceptor.build(
115-
interceptors: [WeatherApiInterceptor()]);
116-
117115
var parsedWeather;
118116
try {
119-
var response = await http.get("$baseUrl/weather?id=$id");
120-
117+
var response = await HttpWithInterceptor.build(
118+
interceptors: [WeatherApiInterceptor()])
119+
.get("$baseUrl/weather", params: {'id': "$id"});
121120
if (response.statusCode == 200) {
122121
parsedWeather = json.decode(response.body);
123122
} else {
@@ -132,5 +131,6 @@ class WeatherRepository {
132131
}
133132
```
134133

135-
### Need help?
134+
### Issue Reporting
135+
136136
Open an issue and tell me, I will be happy to help you out as soon as I can.

example/lib/credentials.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Replace this if you are going to run the example. You can get your own at https://openweathermap.org/
2-
const String OPEN_WEATHER_API_KEY = "b04a4a7c5a71de47d7cdb0c7607c5d14";
2+
const String OPEN_WEATHER_API_KEY = "YOUR-KEY-HERE";

example/lib/main.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,8 @@ class WeatherRepository {
257257
Future<Map<String, dynamic>> fetchCityWeather(int id) async {
258258
var parsedWeather;
259259
try {
260-
final response = await client.get("$baseUrl/weather", params: {
261-
'id': "$id",
262-
});
260+
final response =
261+
await client.get("$baseUrl/weather", params: {'id': "$id"});
263262
if (response.statusCode == 200) {
264263
parsedWeather = json.decode(response.body);
265264
} else {

0 commit comments

Comments
 (0)