This package provides a GoOnline class that can be used to make HTTP requests to a RESTful API. The class is designed to simplify the process of sending HTTP requests by abstracting away the implementation details of the http package. The GoOnline class has methods for sending GET, POST, PUT, and DELETE requests to an API.

Features

This package can be used to send HTTP requests to a RESTful API. Specifically, it provides methods for sending GET, POST, PUT, and DELETE requests to an API, along with the necessary headers for each request. It also includes a method for retrieving an authentication token from the device's SharedPreferences.

The GoOnline class can be instantiated with a base URL for the API, and the postData(), getData(), updateData(), and deleteData() methods can be used to send requests to the API with the provided data. The responses from the API can be handled using the http package's built-in response handling functions.

Getting started

import the package

Usage

import 'package:flutter/material.dart';
import 'package:go_online/go_online.dart';

class MyWidget extends StatelessWidget {
final api = GoOnline();

@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () async {
//Your BaseURL
String baseURL='https://www.example.com';
goOnline.baseurl=baseURL;
final data = {'name': 'John', 'email': 'john@example.com'};
//Using the POST method
final response = await api.postData(data, '/users');
print(response.body);
},
child: Text('Send Request'),
);
}
}
 var goOnline = GoOnline();
//Your BaseURL
String baseURL='https://www.google.com';
goOnline.baseurl=baseURL;
var tokenKey='yourTokenFromSharedPreference';
goOnline.token=tokenKey;

//Using the Get method
var fetch = await goOnline.getData('/search?q=Rarible');
print(fetch.body);
var data = {'name': 'John', 'email': 'john@example.com'};
var response = await goOnline.postData(data, 'users');
var fetch = await goOnline.getData('demo.com/api');
print(fetch.body);

print(response.body);


var responseUpdate = await goOnline.updateData(data, 'users/1');
print(responseUpdate.body);

var responseDelete = await goOnline.deleteData('users/1');
print(responseDelete.body);

Additional information

Visit Flutter.dev

Libraries

go_online