# http **Repository Path**: mpflutter-plugins/http ## Basic Information - **Project Name**: http - **Description**: A composable API for making HTTP requests in Dart. - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-04-16 - **Last Updated**: 2021-07-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README A composable, Future-based library for making HTTP requests. [![pub package](https://img.shields.io/pub/v/http.svg)](https://pub.dev/packages/http) [![Build Status](https://github.com/dart-lang/http/workflows/Dart%20CI/badge.svg)](https://github.com/dart-lang/http/actions?query=workflow%3A"Dart+CI"+branch%3Amaster) This package contains a set of high-level functions and classes that make it easy to consume HTTP resources. It's multi-platform, and supports mobile, desktop, and the browser. ## Using The easiest way to use this library is via the top-level functions. They allow you to make individual HTTP requests with minimal hassle: ```dart import 'package:http/http.dart' as http; var url = Uri.parse('https://example.com/whatsit/create'); var response = await http.post(url, body: {'name': 'doodle', 'color': 'blue'}); print('Response status: ${response.statusCode}'); print('Response body: ${response.body}'); print(await http.read('https://example.com/foobar.txt')); ``` If you're making multiple requests to the same server, you can keep open a persistent connection by using a [Client][] rather than making one-off requests. If you do this, make sure to close the client when you're done: ```dart var client = http.Client(); try { var uriResponse = await client.post(Uri.parse('https://example.com/whatsit/create'), body: {'name': 'doodle', 'color': 'blue'}); print(await client.get(uriResponse.bodyFields['uri'])); } finally { client.close(); } ``` You can also exert more fine-grained control over your requests and responses by creating [Request][] or [StreamedRequest][] objects yourself and passing them to [Client.send][]. [Request]: https://pub.dev/documentation/http/latest/http/Request-class.html [StreamedRequest]: https://pub.dev/documentation/http/latest/http/StreamedRequest-class.html [Client.send]: https://pub.dev/documentation/http/latest/http/Client/send.html This package is designed to be composable. This makes it easy for external libraries to work with one another to add behavior to it. Libraries wishing to add behavior should create a subclass of [BaseClient][] that wraps another [Client][] and adds the desired behavior: [BaseClient]: https://pub.dev/documentation/http/latest/http/BaseClient-class.html [Client]: https://pub.dev/documentation/http/latest/http/Client-class.html ```dart class UserAgentClient extends http.BaseClient { final String userAgent; final http.Client _inner; UserAgentClient(this.userAgent, this._inner); Future send(http.BaseRequest request) { request.headers['user-agent'] = userAgent; return _inner.send(request); } } ```