Integrated Haskell Platform

Learn how to configure IHP for use with Filebase.

What is Integrated Haskell Platform?

Integrated Haskell Platform, or IHP, is a full-stack framework developed to focus on rapid application deployment that utilizes robust code. IHP features a fully managed development environment, integrated development tooling, and quick response times within your production environment.

IHP has native integration for Filebase, making uploading to Filebase within your IHP code a single, seamless function. That means there’s no configuration of Filebase settings or endpoints needed, just your Filebase Access and Secret key pair.

Read below to learn how to use IHP with Filebase.

Prerequisites:

1. Open your IHP Config/Config.hs file.

Insert the following line to import the IHP.FileStorage.Config package:

import IHP.FileStorage.Config

2. Next, in the same file, add the following code snippet to call the function initFilebaseStorage:

module Config where

import IHP.Prelude
import IHP.Environment
import IHP.FrameworkConfig
import IHP.FileStorage.Config

config :: ConfigBuilder
config = do
    option Development
    option (AppHostname "localhost")

    initFilebaseStorage "FILEBASE_BUCKET_NAME"

Replace FILEBASE_BUCKET_NAME with your Filebase bucket name.

3. To connect to Filebase, you will need to set environment variables that contain your Filebase Access and Secret keys.

You can do so with the commands:

export FILEBASE_KEY="FILEBASE ACCESS KEY"

export FILEBASE_SECRET="FILEBASE SECRET KEY"

You can also set these as static variables in your IHP ./start script:

#!/usr/bin/env bash
# Script to start the local dev server

# ...

export FILEBASE_KEY="FILEBASE ACCESS KEY"         
export FILEBASE_SECRET="FILEBASE SECRET KEY"  

# Finally start the dev server
RunDevServeras

4. To upload your data from IHP to Filebase using this configuration, use the following syntax:

action UpdateCompanyAction { companyId } = do
    company <- fetch companyId
    company
        |> fill @'["name"]
        |> uploadToStorage #logoUrl
        >>= ifValid \case
            Left company -> render EditView { .. }
            Right company -> do
                company <- company |> updateRecord
                redirectTo EditCompanyAction { .. }

This assumes that data is in the following schema:

CREATE TABLE companies (
    id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
    name TEXT NOT NULL,
    logo_url TEXT DEFAULT NULL
);

If you have any questions, please join our Discord server, or send us an email at hello@filebase.com

Last updated