Code Monkey home page Code Monkey logo

google-cloud's Introduction

Haskell library to access Google Cloud APIs

The library is incomplete. I only implemented the functions which I need in my own projects. But the basic infrastructure is there so that adding new API endpoints is relatively easy.

Access Token

To interact with the Google Cloud API you need an access token. The easiest way to obtain one is through the metadata service. That only works on instances which run in the Google Cloud and have a service account attached to them.

Cloud monad

All actions which interact with the Google Cloud API run in the Cloud monad. The monad wraps IO, Except and Reader. You get convenience functions to send out HTTP requests and parse responses. The monad also acts as a cache for some frequently used values (such as the access token). All synchronous exceptions are caught and transformed into an Error.

Handle

To run a Cloud action you need a Handle. Because it is relatively expensive to create a handle, you should create one for your whole application. You can either use a convenience function which creates a new Handle with sensible defaults (createHandle), or you can use one which gives you more options to customize the handle (mkHandle).

Example

This code uploads a ByteString into a Google Cloud Storage bucket.

{-# LANGUAGE OverloadedStrings #-}

import Google.Cloud         (newHandle, evalCloud)
import Google.Cloud.Storage (Bucket(..), Name(..), uploadMedia)

main :: IO ()
main = do
    let bucket = Bucket "test-bucket-123"
        name   = Name "file/name.txt"

    h <- createHandle
    evalCloud h $ do
        uploadMedia bucket name "file body" "application/octet-stream"

google-cloud's People

Contributors

werehamster avatar lackita avatar

Stargazers

Luke Meyers avatar Wang avatar Marco Z avatar Tim Kersey avatar Adrien Haxaire avatar Utkarsh Upadhyay avatar Xe Iaso avatar

Watchers

 avatar James Cloos avatar  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.