Dart Web API Template Using Google Shelf Framework and Postgres Drivers, read readme to learn how to use

Overview

Shelf Web Framework Template

by Alex Merced of AlexMercedCoder.com

Cloning the Template

git clone https://github.com/AlexMercedCoder/DartShelfPostgresTemplate.git projectName

or if you have NPM

npx degit AlexMercedCoder/DartShelfPostgresTemplate#main projectName

Folder Structure

  • server.dart: the entry file that kick starts the server

  • cors.dart: The cors header, add this into your responses like in the existing routes

  • controllers: folder for holding routers, HomeController has the main router and you can following the patter display by TestController to mount additonal routers.

Deployment to Heroku using Heroku CLI

  • create a git repo and commit your project

    • git init
    • git add .
    • git commit -m "first commit"
  • heroku create projectName

  • heroku config:set DART_SDK_URL=https://storage.googleapis.com/dart-archive/channels/stable/release/2.12.1/sdk/dartsdk-linux-x64-release.zip

  • heroku config:add BUILDPACK_URL=https://github.com/igrigorik/heroku-buildpack-dart.git

  • heroku config:set DART_BUILD_CMD="./dart-sdk/bin/dart compile exe web/server.dart"

  • git push heroku master

  • API Deployed!!

Heroku Database Setup

Setting Up The Database

  • head to the heroku dashboard for your project

  • go to the resources tab

  • provision a free heroku postgres database

  • go the database dashboard, under settings you'll find the database credentials

  • use those credentials to add the following heroku config vars

DB_HOST
DB_PORT
DB_DATABASE
DB_USERNAME
DB_PASSWORD
  • you'll see a command like this that will let us access the psql shell for the database so we can create our table. heroku pg:psql postgresql-objective-XXXX --app projectname

  • create your tables

  • in connection.dart add useSSL in the list of arguments this.conn = PostgreSQLConnection(host, port, database, username: username, password: password, useSSL: true); and push your code again your api will be deployed!

DATABASE CONNECTION

Environment Variables for Database Settings

  • DB_HOST
  • DB_PORT
  • DB_DATABASE
  • DB_USERNAME
  • DB_PASSWORD

These can be changed in connection.dart

the test.dart file in connection folder is a good tool for testing out database queries and your models

Models

A Sample model is in the models folder that you can copy to create your own by modifying their methods as needed.

follow the patterns in initiateModel and the /getall route in testController to see how to use your model in your routes.

Migrations

I'm using the raw postgres drivers, so no migrations. So you'll need to create the database and tables for your models to work.

You might also like...

This Repository is contain about learn Flutter and Dart [Learn]

Flutter-Dart-Code-Learn-Journey This Repository is contain about learn Flutter and Dart [Learn] Introduction Learn Dart Data Type Control Flow Collect

Jan 11, 2022

Flutter getx template - A Flutter Template using GetX package for State management, routing and Dependency Injection

Flutter getx template - A Flutter Template using GetX package for State management, routing and Dependency Injection

Flutter GetX Template (GetX, Dio, MVVM) This Flutter Template using GetX package

Aug 27, 2022

Simple tool to open WhatsApp chat without saving the number, developed using Google's Flutter Framework. for Android/ IOS/ Desktop/ Web

Simple tool to open WhatsApp chat without saving the number, developed using Google's Flutter Framework. for Android/ IOS/ Desktop/ Web

OpenWp Simple tool to open WhatsApp chat without saving the number Explore the docs » View Demo · Report Bug · Request Feature Table of Contents About

Nov 1, 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

Dec 13, 2022

In this video we will learn how to Create CRUD Rest API for our Flutter application using NODEJS API.

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

Dec 30, 2022

A note-taking app powered by Google services such as Google Sign In, Google Drive, and Firebase ML Vision.

A note-taking app powered by Google services such as Google Sign In, Google Drive, and Firebase ML Vision.

Smart Notes A note-taking app powered by Google services such as Google Sign In, Google Drive, and Firebase ML Vision. This is an official entry to Fl

Oct 26, 2022

A google browser clone which is made by using flutter and fetching the google search api for the search requests.

A google browser clone which is made by using flutter and fetching the google search api for the search requests.

google_clone A new Flutter project. Project Preview Getting Started This project is a starting point for a Flutter application. A few resources to get

May 31, 2022
Comments
Owner
Alex Merced
Instructor at General Assembly and Full Stack Developer for Crossfield Digital. Hundreds of instructional videos at devNursery.com
Alex Merced
Weather app using Bloc architecture pattern & generic HTTP client with interface implementation and much more for more detail read Readme

weather Weather application for current weather, hourly forecast for 48 hours, Daily forecast for 7 days and national weather alerts. How to Run Insta

Jibran Ahmed SiddiQui 9 Oct 29, 2022
Flutter project template with BloC architecture. Implemented many feature as stated in README

Flutter Project Template Using BloC Implementations Theme switching Advanced Routing Bloc Observer for debugging Hydrated Cubit for holding value even

Baran Açıkgöz 9 Dec 10, 2022
A simple web API to generate images from a url, made using shelf package.

Webshot API Yet another simple webshot API but written in dart and built using Shelf library to generate images from url. This is really useful for li

wrench 15 Oct 19, 2022
(Full-stack) Fully functional social media app (Instagram clone) written in flutter and dart with backend node.js and Postgres SQL.

Photoarc A Fully functional social media app written in flutter and dart using node.js and Postgres SQL as backend. Backend Repository Demo Download t

Ansh rathod 59 Jan 5, 2023
Buildpack dart - A server app built using Shelf, configured to enable running with Docker

Hosted at https://dart-buildpack-demo-ruyjilv5wq-uc.a.run.app/ Buildpack defined

Kevin Moore 12 Dec 15, 2022
Tasky-Mobile-App - A task manager built with Flutter, Serverless, Postgres, Firebase

Tasky Mobile App A project management mobile app This project is an implementati

Etornam Sunu 137 Dec 31, 2022
A server app built using Shelf, configured to enable running with Docker

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

Tornike Gogberashvili 1 Jan 26, 2022
A server app built using Shelf, configured to enable running with Docker

A server app built using Shelf, configured to enable running with Docker. Project Structure Running the sample Running with the Dart SDK You can run t

null 0 Jan 12, 2022
A server app built using Shelf, configured to enable running with Docker.

A server app built using Shelf, configured to enable running with Docker.

RAHUL SHARMA 1 May 23, 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.

Flutter Fish 3 Dec 27, 2022