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

Related tags

Templates backbone
Overview

The Backbone Dart Backend Framework

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

Package Pub
backbone pub package
backbone_cli pub package

Quick Start

# Activate from pub.dev
dart pub global activate backbone_cli
# Download example API spec
curl https://raw.githubusercontent.com/mtwichel/backbone/main/example/openapi.yaml --output openapi.yaml
# Generate the API
backbone generate --new

You can read the full documentation here

You might also like...

Netflix app UI clone using bloc,Rest API and TMDB for API key

netflix_flutter project_using_bloc packages Used flutter_bloc json_serializable get_it dio A few resources to get you started if this is your first Fl

Nov 25, 2022

Flying Fish is full-stack Dart framework - a semi-opinionated framework for building applications exclusively using Dart and Flutter

Flying Fish is full-stack Dart framework - a semi-opinionated framework for building applications exclusively using Dart and Flutter.

Dec 27, 2022

A Very Good Blog App using Flutter, flutter_bloc, django rest framework for backend✨

A Very Good Blog App using Flutter, flutter_bloc, django rest framework for backend✨

Very Good Blog App - Blog sharing Features Login, register, manage personal information. Compose, edit, post blog to share with everyone. Like, save b

Nov 27, 2022

Get google api credentials - A Dart CLI app to obtain credentials for accessing Google APIs

get_google_api_credentials A Dart CLI app to obtain credentials for accessing Go

Jan 28, 2022

A dart package to interact with the WooCommerce REST API.

A dart package to interact with the WooCommerce REST API.

WooCommerce SDK for Dart A dart package to interact with the WooCommerce API (now with null-safety). It uses OAuth1.0a behind the scenes to generate t

Dec 28, 2022

Developed using Dart & Flutter & Rest Api & Dio & Bloc & SharedPreferenes.

Developed using Dart & Flutter & Rest Api & Dio & Bloc & SharedPreferenes.

This is an ecommerce app which contain Many features like : Sign in , Sign up , Verify Email , log out. Fetch Products Data Search for any product Add

Nov 3, 2022

Create dart data classes easily, fast and without writing boilerplate or running code generation.

Create dart data classes easily, fast and without writing boilerplate or running code generation.

Dart Data Class Generator Create dart data classes easily, fast and without writing boilerplate or running code generation. Features The generator can

Feb 28, 2022

Sibyl App written with Dart/Flutter. (My first experience in writing a real android app in flutter).

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

Feb 17, 2022

Prism is a beautiful open-source wallpapers app for Android. It is built with Dart on top of Google's Flutter Framework.

Prism is a beautiful open-source wallpapers app for Android. It is built with Dart on top of Google's Flutter Framework.

Prism Prism is a beautiful open-source wallpapers app for Android. It is built with Dart on top of Google's Flutter Framework. Prism brings you exclus

Dec 31, 2022
Comments
  • backbone_cli readme.md is outdated

    backbone_cli readme.md is outdated

    I'm following the instructions here: https://github.com/mtwichel/backbone/tree/main/packages/backbone_cli

    I ran dart pub global activate backbone and it was successfully installed (version 0.0.1-dev.13) but when I run any backbone command I get:

    zsh: command not found: backbone
    

    I tried running the command as follow but also got an error:

    [~] dart pub global run backbone help
         Could not find bin/backbone.dart in package backbone.
    

    Side note: The link for the open api example in backbone_cli readme is broken, it should be: https://github.com/mtwichel/backbone/blob/main/packages/backbone_cli/example/openapi.yaml

    opened by osaxma 4
  • [PROPOSAL] Make Backbone work in-code, not from an OpenAPI Spec

    [PROPOSAL] Make Backbone work in-code, not from an OpenAPI Spec

    Hey everyone 👋 first off I want to share a thank you to everyone that has checked out the package and shown interest! We'll figure out Dart on the server best practices together! 💙

    My Experience With Backbone

    While the current iteration of backbone works, there are a few issues I've come across:

    1. Writing an Open API spec by hand in YAML isn't fun. There are extensions that can improve it, but it still isn't as easy as writing Dart code.
    2. When making the Open API spec, picking an HTTP verb, route, and where to put params (in the query, path, headers, or request body) all take mental energy that I don't want to think about. Almost every time I just want to write a Dart function that I can run on a server and call from the client and I don't care what happens in between.
    3. I personally don't like backbone is its own CLI. We all already have too many CLI commands to remember, backbone shouldn't be one of them.

    My Proposal

    I would like to change backbone so that instead of writing an Open API spec and generating code from there, you write the Dart backend code, and it generates the client code and an Open API spec (for documentation). The code you write would look something like this:

    @CloudFunction()
    Future<GetItemsResponse> getItems(GetItemsRequest request, RequestContext context) async {
      // connect to db and get the items
    }
    

    The RequestContext would still contain a logger, the raw shelf request, userId, and dependency caching that backbone currently has. The GetItemsResponse and GetItemsRequest objects would just be regular Dart objects that can be serialized (have a fromJson and toJson method)

    You would then use the build_runner package to generate your code. (dart run build_runner build). It would generate a client library for calling your functions that would look something like this:

    class ItemsRepository {
      final BackboneApi api;
    
      // ...
    
      Future<List<Items>> getItems(String group) async {
        try {
          final response = await api.getItems(
            GetItemsRequest(group: group),
          );
          return response.items;
        } on BadRequestException catch (e) {
          // handle issues with the request being bad
        } catch (e) {
          // handle other exceptions thrown by the backend function
        }
      }
    }
    

    Challenges to This Proposal

    Objects Shared Between Frontend and Backend

    Right now, backbone generates 3 packages:

    • backend
    • frontend
    • functions_objects (request and response objects shared between the frontend and backend)

    However, if you're defining the shared objects by hand in Dart, then you would probably put them in your backend package. Thus, for the frontend to use them, it would have to depend on the backend in its pubspec, which I don't love. Of course you could put your functions objects in their own package when you write them, but I don't think backbone could enforce that.

    Mason

    Right now, backbone uses Mason internally to generate the source code. It seems natural to use the Mason CLI to build your code (ie mason make backbone), and I would love to make it that easy. However, that would be tough because the configuration is stored as plain Dart code. Anyone who has ideas/experience merging the build_runner package and mason together, please share!

    RPC vs REST

    This point gets a bit nerdy, so be prepared 🤓 😆

    Background

    Two of the bigger theories for designing a web API are Remote Procedure Call (RPC) and Representational State Transfer (REST). As I understand it, from a high level:

    • In RPC, the backend defines a set of functions the frontend can call much like an interface of a Dart package (for example, getItems). They need to be documented because you'll need to know what methods are available to you and how to use them. Also, each function is generally specific to a single-use case.
    • In REST, the backend defines paths to entities and uses HTTP verbs to define what actions can be taken (ie the path /items points to all the Items in the system. A POST call to /items would add a new item, whereas a 'GET' call to /items/3 would retrieve the item with id 3). In theory, they don't need to be documented because they follow standard HTTP protocols, and each route can be used for different use-cases because when you retrieve an entity, you get the entire thing.
    • Of course, there's also gRPC, which is a specific protocol that implements an RPC style API, GraphQL, which is a distinct style from the other two, and probably others as well. I'm just focusing on the two I think are most relevant to the conversation.

    Here are some resources I've read/watched to better understand the topic:

    The Issue

    Right now, backbone uses an Open API spec, which doesn't dictate a style you should use to design your API; it simply allows all the HTTP protocols to be used. You as the developer gets to decide if you follow a REST or RPC pattern. With this change, backbone forces an RPC style API because it takes functions from the backend and exposes them to the frontend. You won't get any control over your routes or HTTP verbs or anything like that. Thus, I think it would be impossible to make REST APIs with backbone, only RPC style APIs.

    Feedback Wanted

    If you've made it this far, here are some questions I'd love opinions on:

    • Do you use backbone or similar tools and agree with the issues I have with them?
    • Do you think this proposal would solve them?
    • Are you worried about not using Mason?
    • Do you have an RPC vs REST take? Is losing the ability to make a REST API a worthy concern?
    • Any other thoughts on the proposal :)

    Thank you again to the wonderful Dart community, and I look forward to your ideas 💡 💙 🚀

    feedback wanted 
    opened by mtwichel 0
Owner
Marcus Twichel
Director of Technology at @city-brew-coffee
Marcus Twichel
Bhagavad Gita app using flutter & Bhagavad-Gita-API is A lightweight Node.js based Bhagavad Gita API [An open source rest api on indian Vedic Scripture Shrimad Bhagavad Gita].

Gita Bhagavad Gita flutter app. Download App - Playstore Web Application About Bhagavad Gita app using flutter & Bhagavad-Gita-API is A lightweight No

Ravi Kovind 7 Apr 5, 2022
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

Albert Oboh 43 Oct 4, 2022
Scouter is a package which was made following the goal to provide a NestJS-like experience to Dart Developers that want to develop Rest APIS

Scouter is a package which was made following the goal to provide a NestJS-like experience to Dart Developers that want to develop Rest APIS Features

Vinicius Amélio 3 Sep 12, 2022
A zero-dependency web framework for writing web apps in plain Dart.

Rad Rad is a frontend framework for creating fast and interactive web apps using Dart. It's inspired from Flutter and shares same programming paradigm

null 70 Dec 13, 2022
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
Intel Corporation 238 Dec 24, 2022
A thought experiment on writing a strange API for Dart.

Operator Frog ?? What is Operator Frog Operator Frog is a < 24h thought experiment that I did. I wanted to know if we could write a strange looking AP

Jochum van der Ploeg 19 Dec 8, 2022
FLutter Api Integration - Flutter Rest API Integration

Flutter_Rest_Api_integration Flutter_Rest_Api_integration. Preview How To Use To

Rahul Ranjan Singh 0 Feb 17, 2022
Movie API Use Rest And Restful API

movie_api use rest and restful api The home screen fetches data from the Episodate API and shows a list of popular shows. The details screen and the s

Le Gia Huy 1 Dec 5, 2022
In this video we will learn how to Create CRUD Rest API for our Flutter application using NODEJS API.

Flutter CRUD Using NodeJS API In this video we will learn how to Create CRUD Rest API for our Flutter application using NODEJS API. ?? Packages Used h

SnippetCoder 14 Dec 30, 2022