medz / spry Goto Github PK
View Code? Open in Web Editor NEWSpry - A HTTP middleware framework for Dart to make web applications and APIs server more enjoyable to write.
Home Page: https://spry.fun
License: MIT License
Spry - A HTTP middleware framework for Dart to make web applications and APIs server more enjoyable to write.
Home Page: https://spry.fun
License: MIT License
After practicing in many projects, we found many shortcomings of Spry.
I'm planning an optimization for version 3.0 and am eager to hear everyone's suggestions for changes.
When I implemented spry_multer in my project it added unnecessary logs in my command-line.
I don't think that it should be done as it degrades the raw performance and also it pollutes the logs which are not required.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
This repository currently has no open or pending branches.
package.json
vitepress ^1.1.4
.github/workflows/test.yml
actions/checkout v4
dart-lang/setup-dart v1
packages/spry/pubspec.yaml
logging ^1.2.0
path ^1.9.0
routingkit ^0.2.0
webfetch ^0.0.16
lints >=3.0.0 <5.0.0
test ^1.23.1
dart ^3.2.0
When writing HTTP server related tests, in most cases, we don't want actually start a HTTP server and use HTTP client to fetch the response, it will impact the testing execution time and write more redundant code.
Sometime, developers need to test single endpoint without routing to guarantee that the handler is working as expected behavior.
API example:
class SpryTestingServer {
Future<HttpResponse> sendSingle(FutureOr Function(HttpRequest) handler, [void Function(HttpRequest)? configure]);
}
Usage example:
import 'dart:io';
import 'package:spry/testing.dart';
import 'package:test/test.dart';
void main() {
test('expect remote server respond correct payload', () {
final spryServer = SpryTestingServer();
Future handle(HttpRequest request) async {
return {'success': 'true', 'data': 'ok'};
}
final res = await spryServer.sendSingle(handle, (req) {
req.write(json.encode({'clientId': 'e93b5045-ed30-4eec-aaab-1cd4c9cb8eb5', 'action': 'updateDeviceStatus', 'payload': {'battery': 80, 'voltage': 3.2, 'current': 0.5, 'networkQuality': 'GOOD'}}));
});
expect(res.statusCode, equals(200));
expect(await res.asJson(), equals({'success': true, 'data': 'ok'}))
});
}
API example:
class SpryTestingServer {
void addHandler(String method, String path, FutureOr Function(HttpRequest) handler);
Future<HttpResponse> send(String method, String path, [void Function(HttpRequest)? configure]);
}
Usage example:
import 'dart:io';
import 'package:spry/testing.dart';
import 'package:test/test.dart';
void main() {
test('expect remote server respond correct payload', () {
final spryServer = SpryTestingServer();
Future getDevice(HttpRequest request) async {
return {'success': 'true', 'data': {'deviceId': 'SN2305830131'}};
}
Future updateDevice(HttpRequest request) async {
return {'success': 'true', 'data': 'ok'};
}
spryServer.addHandler('GET', '/api/v1/device/{deviceId}', getDevice);
spryServer.addHandler('POST', '/api/v1/device/{deviceId}', updateDevice);
final res = await spryServer.send('GET', '/api/v1/device/SN2305830131', (req) {
req.write(json.encode({'clientId': 'e93b5045-ed30-4eec-aaab-1cd4c9cb8eb5', 'action': 'updateDeviceStatus', 'payload': {'battery': 80, 'voltage': 3.2, 'current': 0.5, 'networkQuality': 'GOOD'}}));
});
expect(res.statusCode, equals(200));
expect(await res.asJson(), equals({'success': true, 'data': 'ok'}))
});
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.