drf_client 0.0.3 copy "drf_client: ^0.0.3" to clipboard
drf_client: ^0.0.3 copied to clipboard

A complete REST API client for Django Rest Framework based backends, empowering you to build your app effortlessly without reinventing the wheel. Supports Django OAuth Toolkit, SimpleJWT, and token st [...]

Helps you to automatically authenticate and store tokens and refresh them, also make api requests using them.

Features #

  • ✅ Automatically store tokens using Flutter Secure Storage
  • ✅ Automatically refresh tokens
  • ✅ Supports Oauth2 by Django Oauth Toolkit
  • ✅ Easy REST API call with auth credentials
  • ✅ More coming soon ...

Getting started #

To start using package, add it to your dependencies by running this:

flutter pub add drf_client

or add this line into your pubspec.yaml under dependencies:

dependencies:  
  flutter:  
    sdk: flutter
  # your other dependencies ...
  
  drf_client: <latest_version>

Then import the package in desired files:

import 'package:drf_client/drf_client.dart'; 

Enjoy coding!

Usage #

Firstly, initialize the config:


  void main() {
  
  // existing code
  
    DrfClient client = DrfClient();
    client.addConfig('your-app', DrfConfig(
      authType: AuthType.drfBuiltInAuth,
      baseUrl: 'https://your-app.com/api',
      tokenUrl: 'https://your-app.com/api/token',
      refreshTokenUrl: 'https://your-app.com/api/token/refresh',

      usernameField: 'username', // default username, change this if you are using custom user model in django
      passwordField: 'password', // def password, change this if you changed password field in you user model
      refreshField: 'refresh_token', // change this to comply with your token refresh logic if JWT used
      

      // Set this if u are using Authorization Code over Django-oauth-toolkit
      // oauthConfig: OauthConfig(
      // clientId: "",
      // clientSecret: "",
      // authorizationEndpointUrl: "https://ilmchat.com/auth/authorize/",
      // redirectScheme: 'you-app-shceme'
      //
      // )
    ));
  }
    

You can also set multiple config so that you can make request and authenticate multiple django servers at the same code by giving specific app name in config.

Authenticating users #

via drfBuiltInAuth:


DrfClient client = DrfClient();

client.loginDrfBuiltIn()


making requests #


DrfClient client = DrfClient();

client.get() // post() put() patch() delete()


It will use stored user token in requests if logged in. You can remove Token from auth header by includeToken: false

1
likes
0
pub points
26%
popularity

Publisher

verified publishertijorat.org

A complete REST API client for Django Rest Framework based backends, empowering you to build your app effortlessly without reinventing the wheel. Supports Django OAuth Toolkit, SimpleJWT, and token store/refresh using Shared Preferences.

Homepage

License

unknown (LICENSE)

Dependencies

app_links, flutter, flutter_secure_storage, http, oauth2, url_launcher, win32_registry

More

Packages that depend on drf_client