hequest

Last updated:

0 purchases

hequest Image
hequest Images
Add to Cart

Description:

hequest

Simple and hackable request for dart.
Installing #


Add dependencies to pubspec.yaml
dependencies:
hequest:
git:
url: https://github.com/teixeirazeus/hequest
copied to clipboard


Run pub get.
flutter pub get
copied to clipboard


Import package.
import 'package:hequest/hequest.dart';
copied to clipboard


Using #
Hequest was created with simplicity in mind to handle multiple API requests.
You start by declaring an object of type Hequest and passing the baseUrl of your api.
final githubApi = Hequest(baseUrl: 'https://api.github.com');
copied to clipboard
GET #
final response = await githubApi.get('/users/teixeirazeus');
copied to clipboard
POST #
final response = await githubApi.post('/users/teixeirazeus', body: {
'name': 'Zeus Teixeira',
});
copied to clipboard
PUT #
final response = await githubApi.put('/users/teixeirazeus', body: {
'name': 'Zeus Teixeira',
});
copied to clipboard
DELETE #
final response = await githubApi.delete('/users/teixeirazeus');
copied to clipboard
JWT #
All requests support sending jwt token.
To use to use the WithToken postfix and pass the token as a parameter.
final response = await githubApi.getWithToken('/users/teixeirazeus', token);
copied to clipboard
Tips #
It is highly recommended that you use try catch to handle errors. Along with a larger abstraction with a class for each endpoint of your api.
class GithubApi {
final Hequest _hequest;

GithubApi(this._hequest);

Future<Map> getUser(String username) async {
try {
final response = await _hequest.get('/users/$username');
if (response.statusCode == 200) {
return json.decode(response.body);
} else if (response.statusCode == 404) {
throw Exception('User not found');
} else {
throw Exception('Failed to load user');
}
} catch (e) {
throw Exception('Error getting user');
}
}
}
copied to clipboard
final hequest = Hequest(baseUrl: 'https://api.github.com');
final githubApi = GithubApi(hequest);

final user = await githubApi.getUser('teixeirazeus');
print(user.toString());
copied to clipboard
Contributing #
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.