Giter Site home page Giter Site logo

medz / spry Goto Github PK

View Code? Open in Web Editor NEW
27.0 3.0 3.0 2.44 MB

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

Dart 100.00%
dart freamework spry web http middleware server router

spry's Issues

3.0 idea

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.

Dependency Dashboard

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.

Detected dependencies

bun
package.json
  • vitepress ^1.1.4
github-actions
.github/workflows/test.yml
  • actions/checkout v4
  • dart-lang/setup-dart v1
pub
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

  • Check this box to trigger a request for Renovate to run again on this repository

[Proposal] Testing support

Background

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.

Proposal

Provide APIs for single handler testing

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'}))
  });
}

Provide APIs for multiple endpoints testing with routing

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'}))
  });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.