---
# System prepended metadata

title: HPOS holochain API rewrite

---

# HPOS holochain API rewrite

## Motivation

HPOS holochain API is an express app serving endpoints called by:
- host console UI
- holo-cli (via hpos-holochain-client)
- regression tests
- anything else???

It was never built with a production environment in mind and it obviously needs a re-write.

Benefits of rewrite in rust:
- strong typing of request/response payloads
- rust's emphasis on error handling
- interaction with Holochain via native holochain_conductor_api
- good support of tests in rust (unit, integration)

## API

### `GET /happs/hosted/info`

Returns info on each hosted happ in form of an array of objects with details

Old: /hosted_happs
Query params:
- interval (optional, defaults to 1) - in days (? can I get infinity?)
- quantity (optional, defaults to null) - null for all happs
#### 200
```json
[{
    id: "uhCkkK9aGip7W-QA2psB9ZqFmkTwJLzm_ifuvUTMw1zScpwzKZH97",
    name: "HoloFuel",
    bundleUrl: "https://holo-host.github.io/holo-hosting-app-rsm/releases/downloads/holofuel/0_1_6_alpha0/holofuel.0_1_6_alpha0-dev.happ",
    earnings: 0,
    enabled: true,
    hostedAgents: 0,
    hostedUrls: ["holofuel.dev.holotest.net"],
    id: "uhCkkK9aGip7W-QA2psB9ZqFmkTwJLzm_ifuvUTMw1zScpwzKZH97",
    isPaused: false,
    logoUrl: null,
    name: "HoloFuel",
    special_installed_app_id: null,
    usage: {
        bandwidth: 67157,
        cpu: 0,
        storage: 0
    },
    errors: [{
        message": “servicelogger_not_installed”,
        code: 121
    }]
}]

```

### `GET /happs/hosted/statistics`

Returns statistics on hosting of hosted happs

Old: /usage
Query params:
- interval (optional, defaults to 1) - in days (? can I get infinity?)

#### 200
```json
{
    totalHostedAgents: 0,
    currentTotalStorage: 0,
    totalHostedHapps: 0,
    totalUsage: {
        cpu: 0,
        bandwidth: 0,
    }
}
```

### `GET /happs/core`

Returns an app ID (as installed in holochain) of a core happ. Needed by UI for future zome calls to core happ.

Old: /core_app_version
#### 200
```json
{
    app_id: "core-app:0_3_8_alpha0::f1d1e96b-dc1c-44aa-a714-4a7e45e5aebf"
}
```

#### 404 Not Found

No core-happ found among installed happs

#### 503 Service Unavailable

Couldn't open connection to holochain

#### 504 Gateway Timeout

Websocket connection timeout

### `POST /happs/zome_call`

Execute a zome call to app with `appId` and `roleId`.

Old: /zome_call
request payload:
```json
{
    appId,
    roleId,
    zomeName,
    fnName, 
    payload
}
```
#### 200
Response of the zome call in json format

### `GET /host/preferences`

Get host's default hosting preferences. Hosting preferences are used by service logger in billing for hosting.

Old: /host_preferences
#### 200
```json
{
    max_fuel_before_invoice: 1000,
    max_time_before_invoice: [86400,0],
    price_compute: 0.025,
    price_storage: 0.025,
    price_bandwidth: 0.025
}
```

### `GET /host/earnings`

Returns statistics on earnings from hosting. Includes an array of recent payment requests for hosting.

Old: /host_earnings

```json
{
    earnings: {
        last30days: 1006,
        last7days: 1006,
        lastday: 1006
    },
    holofuel: {
        balance: -6783
    },
    recentPayments: [{
        id: "uhCEkzjtRtrb2Ip5kuZlmfhaG3Z5J_8mX9AkRAECyzBaZpd_5WsJD",
        amount:"1063.425",
        status:"Pending",
        type:"Request",
        direction:"Outgoing",
        createdDate:"1670240844322922",
        completedDate:null,
        expirationDate:null,
        counterparty:"uhCAkJX1suP92Jyp1_G7QbBTAkGEnLZsczbytOI9Zkfg86eMrZJ37",
        note:"Holo Hosting Invoice for \"Publisher Portal\" (...\"l5Y0j\")",
        proofOfServiceToken:"Dj8lClzGtuIU+fJPZHYa5+FyruKgYoSHJz67RN5gApVJXfABssEbgSDaqPRTDmuh7q06jxt6UppQNt9jR+lj3Q==",
        url:null,
        happ: {
            name:"Publisher Portal",
            id:"uhCkktpnpic_oJKfPKvvRsRIKXdCxHLGjcheCe14LEGH6Gchl5Y0j"
        },
        invoiceDetails: {
            start: 1670239509213632,
            end: 1670240844292864,
            service_logs_range: {
                activity:[
                    "uhCkkb0G12f0q0p6Q1fGHNved23i-_g4NAPkzZeTxmwrktUGhQzBz",
                    "uhCkkYPaP2CbZk-79Mfy4bOGGSZRa1uazBMRYYUSRZ2FcEC6PlkjN",
                    "uhCkkrk1SOcS_fTmQerzhhKhyhY9Q9gpKP5vOwsG-69UPu9g2SQOj",
                    "uhCkk1xPHfJuTQdJ6uXObUv2qXilZhO_1Uj64Gzeu8hGdkXuk1bgd",
                    "uhCkk4KPv3I6XxYkceYFKOB9CW9QVLzzN4jgXgMW15xlY9Fropi27",
                    "uhCkk0cQ_j0jIIOvWMJ8LG1DAmxttezjm5zGUt548MAlj1tZrAYbT",
                    "uhCkk3HZpUWyejDRfK-NdPfLrE_jkp-340gCW_KFSpMO31q2Qe_5T",
                    "uhCkkYBzqBsrKgRzQ0UcbzCIViXTTtSxYKZXcV5MC3y-dcEnx_uqg",
                    "uhCkksMBcZyd09qAnsFVRQ1qNwYzMwMnMCMBon8FRCtSvJh8NMSQd",
                    "uhCkkblDZDIACUqwjude0hcWJqHiFYre8fY-Jcky3yye8d3-IXlM7",
                    "uhCkkRJnxcN5BgHPrSvwrU7TqAG68kS_0o9cQzyH7VOsa9KvQfbAQ",
                    "uhCkku7ZRHsUrL1EPhFiC0MspdMjTgQJbn54W88HIMnleRSyBw3Sg",
                    "uhCkkV3ktP36to5d3t3CXpCYNiIX4JwawNqGAuJHB3EZIwcBJfzkH",
                    "uhCkkGFEqpbYbHUQsaV7yM1jpoj01-bEscjZLwRuYaMdN6KOtMqPc",
                    "uhCkkUILSkoX32WLYKcMOVvwo_34sdsfsLkKnWYv_pqmhBOZTmsZA",
                    "uhCkkIfskX1muWCujzmnJUSVDXwyns8H8Zu4XyTjYqWIN6ygkx1hq",
                    "uhCkkqdTz92BVmNHvE6et9Txn_CJpscpohwpt0Rm8Pn7kvyY_F8qU",
                    "uhCkkuPwEwWkRW_WPKAhT7iBEIpuRCvbvHmU00exzcMFcRdKIOx20",
                    "uhCkk-IhSiaVoj78oLB2xtPmKjT0RQf1RMbXb_C-vY2KwAt3wgHmy",
                    "uhCkkvt51SbNd-8elqRXfreKk02uRvXmzjhr_sx2qFBmoZ4Udp5_T",
                    "uhCkkunsi01ojU831_Q--xdgmX2jWKQ7k-UvidO2w11X6EETHmTYQ",
                    "uhCkkynfc1Q746swf66802wbgkWHRMnVFe-_keVe1ZHIz66jBbY4B",
                    "uhCkkJK1lxxgIFF1-JRIgQ9lPofP_oH_03RHIXpEWmaZ1S74DwZL2",
                    "uhCkkEhkl-jYjjbfWIypViqE-fiE4uytuadnbHueQQvw-nH_ZPP9a",
                    "uhCkkRp1CbeILraAuKJlHHDpoo0T3ugKvc_VSUjT1lJ1g1VGzBmpq",
                    "uhCkkRunfSZZsUAQwZi2zXRK-sfd33YzNjaAn81wdYIukRJGCISVu",
                    "uhCkkbDLVRxGdi88Gxv9Mp6UibjO8zPxUxfquVk1rTucQlWS2kTUS",
                    "uhCkkOR_E0rLVKKCMN-r6AL5JyHfn5r295YRNgbqQkppzLCNfrTvy",
                    "uhCkkIy29ipzhA6QVin7Vmzmxwq7k1FTpiI1oXYC-ZzMmtSn4xrRR",
                    "uhCkkYndMnDsGaf_eU9zty7TG_w5qbzmhq-sfsCgHRASA05IVKPbR",
                    "uhCkk5LE8FAjKAEcR3PLLrQnfHPLqmL2vXLjK2YpNUW9acvnSXrbi",
                    "uhCkkKhHaci2jU9wSaeCcqNzoOPjVd6rwi0h029y8Uc0HafZ_vZI-",
                    "uhCkkmZhdcA7O7dolh4ARR86OPB_sKi_JbNr-I2Bwm69UBH9mobsh",
                    "uhCkk-fUPGLUkkEbNMtyN4x4J7tZY0X26s8VpZG2vKhW35m9x6Pll",
                    "uhCkkfxFUQwCWmbStHVr6AN6-ffbxGt5afcv06GB_AJb2CxNvXW3Y",
                    "uhCkkhYwN8rTXc2HqgW8ibC-7vG14qm68LrDhwnQsLg74UmjAxRwR",
                    "uhCkkxxbDsga0AARude7vjpT6WA0dHKBW1i3GRn-AI2didN19zhk5",
                    "uhCkkhEwBlIIOhhK8P64JJ031Gzhz-WA50qpas3WoK94poc-4N_uU"
                ],
                disk_usage: []
            },
            bandwidth: {
                quantity: 42537,
                price: 0.025
            },
            compute: {
                quantity: 0,
                price: 0.025
            },
            storage: {
                quantity: 0,
                price: 0.025
            }
        }
    }]
}
```

### `GET /host/invoices`

Returns all the invoices issued by host.

Query params:
- filter: PAID

Old: /host_invoices
#### 200
```json
[{
        id: "uhCEkzjtRtrb2Ip5kuZlmfhaG3Z5J_8mX9AkRAECyzBaZpd_5WsJD",
        amount:"1063.425",
        status:"Pending",
        type:"Request",
        direction:"Outgoing",
        createdDate:"1670240844322922",
        completedDate:null,
        expirationDate:null,
        counterparty:"uhCAkJX1suP92Jyp1_G7QbBTAkGEnLZsczbytOI9Zkfg86eMrZJ37",
        note:"Holo Hosting Invoice for \"Publisher Portal\" (...\"l5Y0j\")",
        proofOfServiceToken:"Dj8lClzGtuIU+fJPZHYa5+FyruKgYoSHJz67RN5gApVJXfABssEbgSDaqPRTDmuh7q06jxt6UppQNt9jR+lj3Q==",
        url:null,
        happ: {
            name:"Publisher Portal",
            id:"uhCkktpnpic_oJKfPKvvRsRIKXdCxHLGjcheCe14LEGH6Gchl5Y0j"
        },
        invoiceDetails: {
            start: 1670239509213632,
            end: 1670240844292864,
            service_logs_range: {
                activity:[
                    "uhCkkb0G12f0q0p6Q1fGHNved23i-_g4NAPkzZeTxmwrktUGhQzBz",
                    ...
                    "uhCkkhEwBlIIOhhK8P64JJ031Gzhz-WA50qpas3WoK94poc-4N_uU"
                ],
                disk_usage: []
            },
            bandwidth: {
                quantity: 42537,
                price: 0.025
            },
            compute: {
                quantity: 0,
                price: 0.025
            },
            storage: {
                quantity: 0,
                price: 0.025
            }
        }
    }]
```

### `POST /happs/hosted/install`

Installs hosted happ.

Old: /install_hosted_happ
request payload:
```json
{
    name,
    hosted_urls,
    bundle_url,
    dnas
}
```

#### 200
```json

```



### Old: /register_happ

TODO:
???
???


## Technologies

- Rocket framework
- API docs via OpenApi
- error, warn, info, debug logging with env-logger
- well defined syntax of errors
- standard use of HTTP verbs
