Giter Club home page Giter Club logo

firebase-haskell's Introduction

HSpec

Firebase Haskell

A simple Haskell wrapper library for the Firebase API.

Currently implemented Firebase services:

Getting Started

This is a simple explanation of the basic functionalities of the library to get you on track fast.

Firebase Database

First, this is a piece of boilerplate that should be in place before you try the examples:

{-# LANGUAGE OverloadedStrings #-}

module Main (main) where

import Firebase.Database
import Data.Aeson


config = DbConfig { projectId = "your-project-id", authToken = Nothing }

Make a simple read GET request to fetch data from the root location of your project:

main :: IO ()
main = do
  let method = Read
      filter = EmptyFilter
      requestBody = EmptyBody
      location = ""
  response <- dbQuery method config location filter requestBody
  print response

Let's add some filters and nested location to this request. We take advantage of the prepared complexFilter:

main :: IO ()
main = do
  let method = Read
      filter = complexFilter { fOrderBy = Key
                             , fStartAt = Just $ Param (show "h")
                             }
      requestBody = EmptyBody
      location = "languages/functional"
  response <- dbQuery method config location filter requestBody
  print response

You can also make PUT (Write), POST (Push), and PATCH (Update) requests with a defined request body:

data Person = Person String Int
instance ToJSON Person where
    toJSON (Person name age) = object
        [ "name" .= name
        , "age"  .= age
        ]

main :: IO ()
main = do
  let method = Push
      filter = EmptyFilter
      requestBody = Body (Person "Thomas" 23)
      location = "people"
  response <- dbQuery method config location filter requestBody
  print response

You simply define the path and use DELETE (Delete) request to delete data at the location (path):

main :: IO ()
main = do
  let method = Delete
      filter = EmptyFilter
      requestBody = EmptyBody
      location = "dinosaurs/stegosaurus"
  response <- dbQuery method config location filter requestBody
  print response

Running Tests

Since this is a Stack project you simply run a stack test in the root of the repository.

Bulding Documentation

Run stack haddock in the root of the repository to build the documentation.

Contributing

Issues, bugs, and questions may be reported in the GitHub issue tracker for this project.

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

  • Tomáš Patro - Initial work

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

firebase-haskell's People

Contributors

patrotom avatar

Watchers

 avatar

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.