samedi 25 août 2018

JS web framework with transparent/autogenerated client-server data layer

I'm wondering if there's a JS web framework with transparent/autogenerated data layer? To save my time, so I don't have to write all the code by myself.

Let's say I'm writing React Blog app, and communicate with the server using REST API.

I need to write two pieces of data layer, the server side, and its client on the client side.

Something like code below:

1 The business logic itself, resides on the server side:

class BlogAPI {
  async getPosts() {
    const records = await db.query('select * from posts')
    return convertRecordsIntoPostObjects(records)
  }
}

2 Exposing business logic as REST API and writing its client on the client side:

// REST API, this code also resides on the server side.
httpServer.get('/posts', () => blogApi.getPosts())

// And writing a client for it, that code resides on the client side.
class BlogAPIClient {
  async getPosts() {
    http.get('http://server-api-endpoint.com/posts')
  }
}

I'm wondering if there are web frameworks where part 2 is somehow magically autogenerated, so I can save my time and write only the business logic.

P.S. Don't mention GraphQL, it's not what I'm asking.




Aucun commentaire:

Enregistrer un commentaire