Update README.md

This commit is contained in:
Ashita Prasad
2024-12-23 04:33:38 +05:30
parent 1338d95fa8
commit 34021f803b

View File

@ -1,3 +1,209 @@
## postman
Seamlessly work with postman collections.
Seamlessly convert Postman Collection Format v2.1 to Dart and vice versa.
Helps you bring your APIs stored in Postman to Dart and work with them.
Currently, this package is being used by [API Dash](https://github.com/foss42/apidash), a beautiful open-source cross-platform (macOS, Windows, Linux, Android & iOS) API Client built using Flutter which can help you easily create & customize your API requests, visually inspect responses and generate API integration code. A lightweight alternative to postman & insomnia.
### Usage
```dart
import 'package:postman/postman.dart';
void main() {
// Example 1: Postman collection JSON string to Postman model
var collectionJsonStr = r'''
{
"info": {
"_postman_id": "a31e8a59-aa12-48c5-96a3-133822d7247e",
"name": "API Dash",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "26763819"
},
"item": [
{
"name": "GET Requests",
"item": [
{
"name": "Simple GET",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.apidash.dev",
"protocol": "https",
"host": [
"api",
"apidash",
"dev"
]
}
},
"response": []
},
{
"name": "Country Data",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.apidash.dev/country/data?code=US",
"protocol": "https",
"host": [
"api",
"apidash",
"dev"
],
"path": [
"country",
"data"
],
"query": [
{
"key": "code",
"value": "US"
}
]
}
},
"response": []
}
]
},
{
"name": "POST Requests",
"item": [
{
"name": "Case Lower",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n\"text\": \"I LOVE Flutter\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.apidash.dev/case/lower",
"protocol": "https",
"host": [
"api",
"apidash",
"dev"
],
"path": [
"case",
"lower"
]
}
},
"response": []
}
]
}
]
}
''';
var collection = postmanCollectionFromJsonStr(collectionJsonStr);
print(collection.info?.name);
// API Dash
print(collection.item?[0].name);
// GET Requests
print(collection.item?[0].item?[0].request?.url?.protocol);
// https
print(collection.item?[0].item?[0].request?.url?.raw);
// https://api.apidash.dev
// Example 2: Postman collection from JSON
var collectionJson = {
"info": {
"_postman_id": "a31e8a59-aa12-48c5-96a3-133822d7247e",
"name": "API Dash",
"schema":
"https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "26763819"
},
"item": [
{
"name": "GET Requests",
"item": [
{
"name": "Simple GET",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.apidash.dev",
"protocol": "https",
"host": ["api", "apidash", "dev"]
}
},
"response": []
},
{
"name": "Country Data",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.apidash.dev/country/data?code=US",
"protocol": "https",
"host": ["api", "apidash", "dev"],
"path": ["country", "data"],
"query": [
{"key": "code", "value": "US"}
]
}
},
"response": []
}
]
},
{
"name": "POST Requests",
"item": [
{
"name": "Case Lower",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n\"text\": \"I LOVE Flutter\"\n}",
"options": {
"raw": {"language": "json"}
}
},
"url": {
"raw": "https://api.apidash.dev/case/lower",
"protocol": "https",
"host": ["api", "apidash", "dev"],
"path": ["case", "lower"]
}
},
"response": []
}
]
}
]
};
var collection2 = postmanCollectionFromJsonStr(collectionJsonStr);
print(collection2.info?.name);
// API Dash
print(collection2.item?[0].name);
// GET Requests
print(collection2.item?[0].item?[0].request?.url?.protocol);
// https
print(collection2.item?[0].item?[0].request?.url?.raw);
// https://api.apidash.dev
}
```