restful_api 0.0.2
restful_api: ^0.0.2 copied to clipboard
A complete REST API client, empowering you to build your app effortlessly without reinventing the wheel. Supports OAuth2, JWT, and token store/refresh using Shared Preferences.
import 'package:flutter/material.dart';
import 'package:restful_api/restful_api.dart';
void main() {
RestfulApiConfig config = RestfulApiConfig();
config.baseUrl = 'https://smartlib.tijorat.org/api/v1';
config.usernameField = 'mobile';
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({ super.key });
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
RestfulApiConfig config = RestfulApiConfig();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar( title: const Text("Restful API") ),
body: const Center(
child: Text("Salom"),
),
floatingActionButton: FloatingActionButton(
onPressed: ()async{
RestfulApi api = RestfulApi();
Map res = await api.read('books/books');
debugPrint(res.toString());
},
child: const Icon(Icons.login),
),
);
}
}