n_request 0.2.2 copy "n_request: ^0.2.2" to clipboard
n_request: ^0.2.2 copied to clipboard

Simple helper for http requests

Neil's Custom Request #

this is a simple helper project for http request

With this widget, you can: #

  • Make get, post, put, delete request
  • Make a custom request by type
  • Upload multipart files
  • Change headers
  • New! single or multiple WebSocket with restarter and error control!

Example #

await NRequest(
    "http://example.com/post/",
    body  : { "type": 1 },
    files : [ MultipartFile ]
).post((response) {
    if(response.isValid) response.printStatus();
});

Methods #

await NRequest("url").get((response) {});
await NRequest("url").post((response) {});
await NRequest("url").put((response) {});
await NRequest("url").delete((response) {});
await NRequest("url").type(type: RequestType.post).then((response) {});

Setters #

url: String // Required string
headers: Map<String, String>?
token: Map<String, String>?
body: Map<String, dynamic>
files: List<MultipartFile>
timeout: Duration
printRequest: bool
printResponse: bool

ResponseData Properties #

url: String
type: RequestType
status: StatusData
body: dynamic

/// print a colored message, only works in debug mode
printStatus()

StatusData Properties #

type: StatusType
code: int
isValid: bool
description: String

/// get status data message
getMessage(): String

WebSocket #


NSocketData? socketData;
NSocketController? socketController;

socketData = SocketData(
    name      : "Clients socket",
    url       : "ws url",
    function  : (message) => smsFunction(message)
);

// This is a setter and controller if you want to listen conection status
socketData?.addListener(()=> setState(() {}));

socketData?.hasChannelConnection : bool
socketData?.hasSocketConnection : bool


// SUPORT FOR A SINGLE OR MULTIPLE SOCKETS!
socketController = NSocketController.single(socket: socketData)
socketController = NSocketController.group( sockets: [socketData1, socketData2, ...] )

// Start listening; this includes a restarter that attempts to reconnect to the socket
// in case of disconnections or reconnections.
socketController?.listen();

// Always dispose contrllers
@override
void dispose() {
    super.dispose();
    socketData = null;
    socketData?.dispose();
    socketController = null;
    socketController?.closeAll();
}
1
likes
0
points
10
downloads

Publisher

unverified uploader

Weekly Downloads

Simple helper for http requests

Repository (GitHub)
View/report issues

Topics

#request #get #post #put #delete

License

unknown (license)

Dependencies

flutter, http, web_socket_channel

More

Packages that depend on n_request