Code Monkey home page Code Monkey logo

dartive's Introduction

Dartive is an ExpressJS-like wrapper for Dart backend, simplifying the process of defining routes and handling HTTP requests.

Features

  • Route Handling: Define GET , POST, PUT , DELETE and other routes easily and intuitively.
  • Request Parsing: Parse incoming request bodies using built-in JSON decoding and custom data models.
  • Server Configuration: Customize your server host and port with a single line of code.

Installation

Include Dartive in your pubspec.yaml under dependencies:

dependencies:
  dartive: ^version

Then, run dart pub get to fetch the package.

pub package

Usage

Basic Usage

import 'package:dartive/dartive.dart';

void main(List<String> arguments) {
  Dartive.get('/', () {
    return {'message': 'Hello, world!'};
  });

  Dartive.listen(host: '0.0.0.0', port: 8080);
}

Using Models for Request Parsing

import 'dart:convert';
import 'package:dartive/dartive.dart';
import 'models/myModel.dart';

void main(List<String> arguments) {
  Dartive.post('/myEndpoint', (Dartive api) async {
    var body = api.request;
    var parsedData = json.decode(body).map((data) => MyModel.fromJson(data)).toList();
    List<MyModel> modelList = List<MyModel>.from(parsedData);
    return modelList[0];
  });

  Dartive.listen(host: '0.0.0.0', port: 8080);
}

Running Dartive with Dartivemon

You can run the back and front end, coupled with hot reloading with Dartivemon! To run Dartive with Dartivemon, use the command dartivemon be [nameofapp.dart]. This command runs the server on a specific folder.

Recommended File Structure(FeBe)

What is FeBe?

FEBE (FrontEnd BackEnd) is a unified framework that simplifies development across multiple platforms - iOS, Android, Web (WASM), Linux, and Windows - using Dart and Flutter. By structuring your project according to the FEBE framework, you can maintain a single code base for both the backend and frontend, reducing redundancy and improving maintainability.

Single Source of Truth for Models

One of the core benefits of the FEBE framework is that it eliminates the need to maintain separate models for the backend and frontend. Traditionally, you might define one set of models for your backend, and another set for your frontend, duplicating effort and introducing potential inconsistencies.

FEBE solves this by enabling you to define your data models once and use them across your entire app. This not only reduces the amount of code you have to write, but also ensures consistency and accuracy across your application.

Multiplatform Development

Developing applications that run on multiple platforms (iOS, Android, Web, Linux, Windows) has traditionally been a complex and time-consuming process, often requiring separate code bases for each platform.

FEBE simplifies this process by leveraging the capabilities of Dart and Flutter to build multiplatform apps from a single code base. This means you can write your code once, and then compile and deploy it across all supported platforms, saving time and effort.

Dartive and Dartivemon

FEBE integrates with Dartive, an ExpressJS-like wrapper for Dart backend, and Dartivemon, a tool that runs Dart and Flutter applications concurrently and watches for changes in your Dart application to automatically restart it.

File Structure

root
├── example
│   ├── flutter_app
│   ├── model
│   ├── app.dart (run with dartivemon app.dart)
│   └── lib
│       └── main.dart (runs with just dartivemon app.dart or flutter run)

Running FEBE with Dartivemon

To run your FEBE application with Dartivemon, use the command dartivemon be [nameofapp.dart]. This command runs the server on a specific folder.

Notes

Make sure to replace '0.0.0.0' and 8080 with your desired server host and port, respectively. You can define as many routes as needed using Dartive's get and post methods. Use the listen method to start the server after defining your routes.

dartive's People

Contributors

justrach avatar

Stargazers

 avatar Mark Baum avatar Nitish avatar Brendan Cheong avatar Han avatar Tricia Goh avatar Andrea L. avatar  avatar Sng Haoren avatar  avatar Varun Swaminathan avatar  avatar

Watchers

 avatar

Forkers

han3101

dartive's Issues

Security Depth Testing

Need some way to test the headers as well!

  • To see if addition of other state management packages can be used on the server end, to fasten server loads. Probably some way to cache existing code
  • (to be added)

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.