Build an End-to-End Typesafe APIs (Experimental)

Overview

mid

⚠️ warning: the project is still experimental!

so things may change often until a stable version is released.

mid is a tool to build an end-to-end typesafe API in dart. The tool generates an API server and a client library in addition to handling requests and managing communication between the server and the client.

In short:

  • You write this on the server side:

    class App extends EndPoints {
        final Database database;
    
        App(this.database);
    
        Future<UserData> getUserData(int uid) async {
            final user = await database.getUserById(uid);
            return user;
        }
    
        Stream<List<Post>> timeline(int uid) {
            return database.timelineStream(uid);
        }
    
        Future<void> updateProfile(UserProfile profile) {
            await database.updateProfile(profile);
        }
    }
  • And mid enables you to do this on the client side:

    final client = TheClient(url: 'localhost:8080');
    
    final UserData data = await client.getUserData(42); 
    
    final  Stream<List<Post>> posts = await client.timeline(uid); 
    
    final newProfile = profile.copyWith(photoURL: photoURL);
    await client.updateProfile(newProfile); 

See the Quick Start Tutorial to learn how to use mid in no time.

Getting Started

Installation:

dart pub global activate mid

Tutorials:

Examples:

  • Examples will be added SOON to the examples folder.

Documentation

The documentation is being created incrementally within docs folder. Currently the following is available:

Motivation

To have the ability to call the backend code from the frontend in a type safe manner and as simple as calling a function in pure Dart.

Note: mid is not intended to generate a REST API, but to generate an API server that can be seamlessly used by a Dart or Flutter frontend with a minimal effort.

How does it work

mid simply works by converting the public methods for a given list of classes into endpoints on a shelf server by generating a shelf_router and its handlers. In addition, the return type and the parameters types of each method are parsed and analyzed to generate the serialization/deserialization code for each type.

The client library is generated in a similar manner where each class, method, return type and parameter type is regenerated so that each endpoint becomes a simple function.

To support streaming data from the server to the client, shelf_web_socket is used on the server while web_socket_channel on the client.

Additional Notes

Supported Classes

Any class of an EndPoints* type. mid will only expose the public methods of the given class and it'll not expose any of its superclass(es).

* EndPoints is just a type -- for now there's nothing to implement. a class just needs to implement, extend or mixin EndPoints so it can be converted.

Supported Return Types and Method Parameters Types

  • All core Types (int, double, num, bool, String, DateTime, Duration, enum, Uri, BigInt)

  • User defined Classes*

  • Collections (i.e., Map, Set, List) of any of the above.

  • Future or Stream for any of the above.

    * mid is able to serialize user defined classes and their members recursively as long as they have an unnamed generative constructor with formal parameters only (i.e. all parameters using this). An example class would be:

    class UserData {
      final int id;
      final String name;
      final bool isAdmin;
      // `MetaData` must follow the same rules including its members.
      final MetaData? metadata;
    
      // this is what `mid` is looking for (i.e. no assignment in initializer list or constructor body):
      UserData({
        required this.id,
        required this.name,
        this.metadata,
        this.isAdmin = false,
      });
    
      /* you can define your own methods, factory constructors, and whatnot */
    }
You might also like...

A Flutter plugin that provides assets abstraction management APIs without UI integration, you can get assets (image/video/audio) on Android, iOS and macOS.

A Flutter plugin that provides assets abstraction management APIs without UI integration, you can get assets (image/video/audio) on Android, iOS and macOS.

photo_manager Photo/Assets management APIs for Flutter without UI integration, you can get assets (image/video/audio) from Android, iOS and macOS. 提供相

Jan 4, 2023

A library for building REST APIs easily with Dart

A library for building REST APIs easily with Dart modeled after Express JS for Node Js. The library is still a work in progress and open to contributi

Oct 4, 2022

Public interface definitions of Google APIs for Dart and gRPC

Public interface definitions of Google APIs for Dart and gRPC. Getting started I

Feb 23, 2022

The app that i built during the IITM Session on "Working with APIs in Flutter"

api_test A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

Dec 18, 2021

flutter_thrio makes it easy and fast to add flutter to existing mobile applications, and provide a simple and consistent navigator APIs.

flutter_thrio makes it easy and fast to add flutter to existing mobile applications, and provide a simple and consistent navigator APIs.

中文文档 英文文档 问题集 原仓库不再维护,代码已经很老了 最近版本更新会很快,主要是增加新特性,涉及到混合栈的稳定性的问题应该不多,可放心升级,发现问题加 QQ 群号码:1014085473,我会尽快解决。 不打算好好看看源码的使用者可以放弃这个库了,因为很多设定是比较死的,而我本人不打算花时间写

Dec 29, 2022

Maps for Flutter developers. Supports Apple, Bing, and Google APIs.

Overview Cross-platform geographic maps for Flutter applications. Pull requests are welcome! The packages are licensed under the Apache License 2.0. P

Oct 13, 2022

Flutterbodydetection - A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmentation APIs for both static images and live camera stream.

Flutterbodydetection - A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmentation APIs for both static images and live camera stream.

body_detection A flutter plugin that uses MLKit on iOS/Android platforms to enable body pose and mask detection using Pose Detection and Selfie Segmen

Dec 5, 2022

Chat-app-server - Backend layer that exposes some APIs

A server app built using Shelf, configured to enable running with Docker. This sample code handles HTTP GET requests to / and /echo/message Running

Jan 7, 2022

Backbone - A Dart framework for writing REST APIs from an Open API spec

The Backbone Dart Backend Framework A Dart framework for writing REST APIs from

Oct 6, 2022
Owner
osama
osama
A mobile client for the public apis repository, 1400+ free apis to use able to be navigated through your phone :)

Public APIs mobile app Your assistant app that will help you discover and pick the next API for your next development project What it contains, you sa

Gwhyyy 4 Dec 25, 2022
Flutter_ddd - Experimental Flutter project with Domain-Driven Design

flutter_ddd Notes app sample in Dart / Flutter with DDD. This is an outcome of my attempt to understand Domain-Driven Design and consider how I can in

Kabo 90 Dec 18, 2022
:end: A dart package to append either `&` or `and` at the end of a List.

And Game A dart package to append either & or and at the end of a List. Features Appends & or and at the end of the list. Available as method or exten

Tirth 2 Sep 24, 2021
Appwrite is a secure end-to-end backend server for Web, Mobile, and Flutter developers that is packaged as a set of Docker containers for easy deployment 🚀

A complete backend solution for your [Flutter / Vue / Angular / React / iOS / Android / *ANY OTHER*] app Appwrite 0.12 has been released! Learn what's

Appwrite 28.2k Jan 3, 2023
Bhargav Reddy 10 Nov 12, 2022
The Integration Test Helper has pre-configured methods that allow for faster test deployment for end to end (e2e) test coverage.

The Integration Test Helper has pre-configured methods that allow for faster test deployment for end to end (e2e) test coverage (using Android and iOS

The Mobile Applications Community 2 Apr 7, 2022
End to end flutter series for zero to hero flutter devloper.( lang of videos is turkish)

flutter_full_learn A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you start

Veli Bacik 191 Dec 24, 2022
End-to-end mobile app templates that other developers can use during their Flutter development journey.

Flutter UI Templates Welcome Contributors ?? The Robotics Forum always encourages new ideas. Aim ?? Main aim of this repository is to make things fast

The Robotics Forum, VIT Pune 8 Dec 18, 2022
Easily build your Widgets, Avoid parenthesis nesting, easy to build UI, A little like swift-ui.

tenon_mortise Easily build your Widgets, Avoid parenthesis nesting, easy to build UI, A little like swift-ui. Getting Started Usage To use this plugin

JieLiu 4 Dec 15, 2022
A showcase of the most common Flutter animation APIs.

Flutter Animations Gallery This project is a showcase of the most common Flutter animation APIs. Preview Also available as a Flutter web demo. Setting

Andrea Bizzotto 136 Dec 10, 2022