# Cartesify REST - HLF

**URL:** <https://governance.cartesi.io/t/cartesify-rest-hlf/366>\
**Category:** Technical Evolution Plan\
**Tags:** high-level-framework\
**Created:** [February 2, 2024, 1:02am UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366 "2024-02-02T01:02:07Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabio.oshiro](https://dub1.discourse-cdn.com/flex005/user_avatar/governance.cartesi.io/fabio.oshiro/32/34_2.png) [@fabio.oshiro](https://governance.cartesi.io/u/fabio.oshiro)\
**Post date:** [February 2, 2024, 1:02am UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/1 "2024-02-02T01:02:07Z")

</div>

# Cartesify HLF

Bruno aka @sandhilt and I are focused on growing Cartesi’s adoption, especially among web2 developers. Our proposal introduces a REST abstraction layer to the current technology stack, aiming to simplify onboarding. By taking advantage of the familiarity developers have with RESTful architectures, we aim to facilitate the transition from web2 to web3 with minimal effort. This approach aligns with our goal of creating a more developer-friendly ecosystem and expanding Cartesi’s reach within the broader community.

## Statistics

The latest Stack Overflow survey shows that the majority of developers are web developers.

> **[Stack Overflow Developer Survey 2023](https://survey.stackoverflow.co/2023/#section-developer-roles-developer-type)**
>
> In May 2023 over 90,000 developers responded to our annual survey about how they learn and level up, which tools they're using, and which ones they want.

 ![Stackoverflow Survey 2023](https://europe1.discourse-cdn.com/flex005/uploads/poc_dao/original/1X/8f2a497c7de769a1c28d5e44eca34900f8598622.png)

## Some Advantages

1. **Low Learning Curve:**

2. **Widely Adopted:**

3. **Adapting Existing Systems:**

4. **Future evolution:**

5. **Community Adoption:**

6. **Documentation and Tooling:**

## Example

Given this minimal backend code:

```js
const express = require("express")

const app = express();
const port = 8383;
app.use(express.json());

app.post('/hit', (req, res) => {
    res.send({ amount: req.body.amount });
});

app.listen(port, () => {
    console.log(`[server]: Server is running at http://localhost:${port}`);
});

```

The frontend code to make an HTTP POST request to the backend using Cartesify will be:

```ts
const handleHit = async () => {
    const res = await Cartesify.axios.post("/hit", { amount: 1234 });
    console.log(res.data);
}

```

When triggered, the code above will print `{"amount": 1234}` in the console.

## Tech details

 ![Cartesi Tech Diagram](https://europe1.discourse-cdn.com/flex005/uploads/poc_dao/original/1X/36a07b2fff5da73de77d0361cf621c729ed91814.png)

All the REST verbs that make changes to the state (POST, PUT, PATCH, DELETE) will be signed by the private key, possibly using a wallet like MetaMask, and will be implemented using the `advance` command. The GET operation will be implemented using the `inspect` command.

As a web2 developer, we will achieve battle-proof authentication by adding the `msg_sender` to the request headers.

```js
// express code
app.post('/hit', (req, res) => {
    const msgSender = req.get('x-msg_sender');
    res.send({ amount: req.body.amount });
});

```

Additionally, web2 developers will benefit from an atomic operation. If the endpoint returns an error, such as a 4xx or 5xx status code, we will send a `reject` that performs a rollback operation, thanks to the Cartesi technology as pointed out by @gabrielbarros.

### Deposit

We will set up a protected webhook by convention, pointing to /webhooks/deposits, which can be configurable.

```json
{
    "success": true,
    "erc20": "0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1",
    "depositor": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
    "amount": "100",
}

```

---

<div class="post-metadata">

**Author:** ![milton-cartesi](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@milton-cartesi](https://governance.cartesi.io/u/milton-cartesi)\
**Post date:** [February 2, 2024, 2:51pm UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/2 "2024-02-02T14:51:22Z")

</div>

Hi @fabio.oshiro! Very cool approach, I’ve often thought about a nice way of encapsulating things the way you are envisioning. I’ve got a few questions:

1. I’m not sure I understood how your back-end code works. You are running Express inside the machine on port 8383, and there is also a `BackCartesify` service running (in place of the HTTP API) that interacts with the rollup device and calls the Express server?
2. How would you encode vouchers in the back-end? I think `res.send({ ... })` in the back-end would emit a notice, right?
3. How would you retrieve and execute vouchers in the front-end?

---

<div class="post-metadata">

**Author:** ![fabio.oshiro](https://dub1.discourse-cdn.com/flex005/user_avatar/governance.cartesi.io/fabio.oshiro/32/34_2.png) [@fabio.oshiro](https://governance.cartesi.io/u/fabio.oshiro)\
**Post date:** [February 2, 2024, 3:24pm UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/3 "2024-02-02T15:24:11Z")

</div>

> [@milton-cartesi](#):
>
> I’m not sure I understood how your back-end code works. You are running Express inside the machine on port 8383, and there is also a `BackCartesify` service running (in place of the HTTP API) that interacts with the rollup device and calls the Express server?

It’s an idea for a future optimization. If the Cartesi REST concept evolves, we will develop a better solution called “BackCartesify” to access the rollups device directly.

> [@milton-cartesi](#):
>
> How would you encode vouchers in the back-end? I think `res.send({ ... })` in the back-end would emit a notice, right?

The Rollups HTTP Server will still be there to send vouchers and notices. Currently, we are only generating reports, but it’s easy to change.

> [@milton-cartesi](#):
>
> How would you retrieve and execute vouchers in the front-end?

We’re thinking about it. In our initial work with Solana, we handled deposit and voucher execution, etc. We need to revisit this topic because the code is outdated.

---

<div class="post-metadata">

**Author:** ![joao-garcia](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@joao-garcia](https://governance.cartesi.io/u/joao-garcia)\
**Post date:** [February 5, 2024, 2:42pm UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/4 "2024-02-05T14:42:54Z")

</div>

I love the idea of using express and flask for development. The one thing I keep asking myself is, if code 4xx and 5xx sends a reject, shouldn’t the res.send() with status 200 only send “accept” and not notices? (Not saying it should, just raising this point)

---

<div class="post-metadata">

**Author:** ![marcussouza](https://avatars.discourse-cdn.com/v4/letter/m/b9e5f3/32.png) [@marcussouza](https://governance.cartesi.io/u/marcussouza)\
**Post date:** [February 5, 2024, 3:26pm UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/5 "2024-02-05T15:26:10Z")

</div>

Hey there!

I like this approach, especially in terms of Statistics. It makes a lot of sense to bring REST to the game; almost every API project I’ve worked on so far in web2 used REST.

> [@fabio.oshiro](#):
>
> The latest Stack Overflow survey shows that the majority of developers are web developers.

This resonates with the masterclass students, where the majority were web developers, especially JavaScript users.

Just a question: If I understood well, this also changes how developers integrate their frontends with our cartesi backend, right?  
Also, with this approach, can we expect that the time for the data workflow will increase, right?

---

<div class="post-metadata">

**Author:** ![gabrielbarros](https://dub1.discourse-cdn.com/flex005/user_avatar/governance.cartesi.io/gabrielbarros/32/108_2.png) [@gabrielbarros](https://governance.cartesi.io/u/gabrielbarros)\
**Post date:** [February 6, 2024, 4:51pm UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/6 "2024-02-06T16:51:46Z")

</div>

I loved the approach! I think leveraging people’s knowledge of RESTful and the ‘verbs’ to introduce people to the basic concepts of interaction with blockchain is an excellent idea.

If we search for it, we can find issues and limitations with this design, of course, but honestly, as a bridge, this is really good. As the idea of coding a ‘backend’ with such special properties starts to sink into the developer’s mind, they can slowly add more customizations to your framework or even leave it altogether.

---

<div class="post-metadata">

**Author:** ![fabio.oshiro](https://dub1.discourse-cdn.com/flex005/user_avatar/governance.cartesi.io/fabio.oshiro/32/34_2.png) [@fabio.oshiro](https://governance.cartesi.io/u/fabio.oshiro)\
**Post date:** [February 6, 2024, 5:58pm UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/7 "2024-02-06T17:58:56Z")

</div>

> [@marcussouza](#):
>
> Also, with this approach, can we expect that the time for the data workflow will increase, right?

I believe that the time will increase slightly because we will need to perform serialization and deserialization using JSON, as well as the time it takes for the chosen framework to respond.

---

<div class="post-metadata">

**Author:** ![fabio.oshiro](https://dub1.discourse-cdn.com/flex005/user_avatar/governance.cartesi.io/fabio.oshiro/32/34_2.png) [@fabio.oshiro](https://governance.cartesi.io/u/fabio.oshiro)\
**Post date:** [February 6, 2024, 6:06pm UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/8 "2024-02-06T18:06:05Z")

</div>

> [@joao-garcia](#):
>
> I love the idea of using express and flask for development. The one thing I keep asking myself is, if code 4xx and 5xx sends a reject, shouldn’t the res.send() with status 200 only send “accept” and not notices? (Not saying it should, just raising this point)

We are sending a report at the end of the HTTP request. This report is to provide feedback to the frontend with the response from the backend running within the Cartesi Machine.  
And yes!! Additionally, the 200 status code will trigger a `accept` POST request to the /finish endpoint of the rollups server.

---

<div class="post-metadata">

**Author:** ![bmaia18](https://dub1.discourse-cdn.com/flex005/user_avatar/governance.cartesi.io/bmaia18/32/154_2.png) [@bmaia18](https://governance.cartesi.io/u/bmaia18)\
**Post date:** [February 7, 2024, 4:49pm UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/9 "2024-02-07T16:49:11Z")

</div>

Hi Fabio! Im a fundamental advocate of convenience as a roadblock remover for adoption! So whenever I read convenience I tend to give thumbs up 🙂

Thanks for a very detailed proposal and your time on digging into that so important topic!

I have a few questions to learn more:

1 - As I understood this new API will sit on top of the existing HTTP API right?

2 - How that connect with the other HLF that has been developed taking into consideration the HTTP API?

3 - Is there any impact on Sunodo? Sunodo brings a template for builders to use, so I presume the Sunodo template should come with your HLF, right? My goal here is to ensure we have a cohesive experience for developers putting all our improvements aligned within the same developer journey

---

<div class="post-metadata">

**Author:** ![fabio.oshiro](https://dub1.discourse-cdn.com/flex005/user_avatar/governance.cartesi.io/fabio.oshiro/32/34_2.png) [@fabio.oshiro](https://governance.cartesi.io/u/fabio.oshiro)\
**Post date:** [February 8, 2024, 12:27pm UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/10 "2024-02-08T12:27:35Z")

</div>

> [@bmaia18](#):
>
> - As I understood this new API will sit on top of the existing HTTP API right?

Yes, the existing HTTP API will remain the same.

> [@bmaia18](#):
>
> How that connect with the other HLF that has been developed taking into consideration the HTTP API?

We will maintain all other frameworks.

> [@bmaia18](#):
>
> - Is there any impact on Sunodo? Sunodo brings a template for builders to use, so I presume the Sunodo template should come with your HLF, right? My goal here is to ensure we have a cohesive experience for developers putting all our improvements aligned within the same developer journey

Good suggestion! We will take a look at the templates repository to add a REST template.

---

<div class="post-metadata">

**Author:** ![fabio.oshiro](https://dub1.discourse-cdn.com/flex005/user_avatar/governance.cartesi.io/fabio.oshiro/32/34_2.png) [@fabio.oshiro](https://governance.cartesi.io/u/fabio.oshiro)\
**Post date:** [February 18, 2024, 10:16pm UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/11 "2024-02-18T22:16:07Z")

</div>

Hi guys! Take a look at our first example to get a preview of what we’ve been working on: [cartesify-nodejs-rest-example](https://github.com/Calindra/cartesify-nodejs-rest-example).  
Your insights and suggestions are really welcome as we continue to refine and improve our frameworks.

---

<div class="post-metadata">

**Author:** ![diego.sena](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@diego.sena](https://governance.cartesi.io/u/diego.sena)\
**Post date:** [February 22, 2024, 11:29pm UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/12 "2024-02-22T23:29:40Z")

</div>

Hi Guys, we developed an example using Tim’s rock paper scissor tutorial using Cartesify: [GitHub - Calindra/cartesify-rock-paper-scissors: Tim's Rock Paper Scissors example using Cartesify](https://github.com/Calindra/cartesify-rock-paper-scissors). Also you can check a full template (backend and frontend) here: [GitHub - Calindra/cartesify-template: Cartesify Template for Sunodo](https://github.com/Calindra/cartesify-template)

---

<div class="post-metadata">

**Author:** ![fabio.oshiro](https://dub1.discourse-cdn.com/flex005/user_avatar/governance.cartesi.io/fabio.oshiro/32/34_2.png) [@fabio.oshiro](https://governance.cartesi.io/u/fabio.oshiro)\
**Post date:** [March 26, 2024, 1:06am UTC](https://governance.cartesi.io/t/cartesify-rest-hlf/366/13 "2024-03-26T01:06:30Z")

</div>

We are using the Cartesi Store as our lab to give to dev community the best experience.  
Clone the project, install the backend, and run `pnpm run dev`, we expect you to have a backend auto-reload when you edit the code, with `nonodo` running.  
And, of course, an easy way to communicate between the frontend and backend through the Cartesify REST framework.

> **[GitHub - Calindra/cartesi-store](https://github.com/Calindra/cartesi-store)**
>
> Contribute to Calindra/cartesi-store development by creating an account on GitHub.
