pytorch-lightning icon indicating copy to clipboard operation
pytorch-lightning copied to clipboard

(app) Introduce configure_api and Post, Get, Delete, Put HttpMethods

Open tchaton opened this issue 3 years ago • 1 comments

What does this PR do?

After chatting with @lantiga, we thought there is a need to enable users to expose their own API through the App Rest API.

This PR introduces configure_api hook to the LightningFlow and Post, Put, Delete and Get HttpMethods.

from lightning.api import Post
from pydantic import BaseModel

class Model(BaseModel):
    name: str

class FlowAPI(LightningFlow):

    def handler(self, config: Model):
        return {"counter": config.name}

    def configure_api(self):
        return [Post("/api/v1/request", self.handler)]
Screenshot 2022-07-31 at 13 07 46 Screenshot 2022-07-31 at 13 08 43

TODOS: In another PR, rename the queues and unify API with commands.

Does your PR introduce any breaking changes? If yes, please list them.

Before submitting

  • [x] Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • [x] Did you read the contributor guideline, Pull Request section?
  • [x] Did you make sure your PR does only one thing, instead of bundling different changes together?
  • [ ] Did you make sure to update the documentation with your changes? (if necessary)
  • [ ] Did you write any new necessary tests? (not for typos and docs)
  • [x] Did you verify new and existing tests pass locally with your changes?
  • [x] Did you list all the breaking changes introduced by this pull request?
  • [x] Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR. Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

  • [x] Is this pull request ready for review? (if not, please submit in draft mode)
  • [x] Check that all items from Before submitting are resolved
  • [x] Make sure the title is self-explanatory and the description concisely explains the PR
  • [x] Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

tchaton avatar Jul 31 '22 11:07 tchaton

Hey @hhsecond,

I am not entirely sure to understand your question. There isn't a configure_route right now.

The use case is to enable users to register their own external API so they can provide ways for their app to interact with the outside world. Similar to a controlplane.

Within the LightningHPO App, I am using it to enable users to fetch structured information about the app. I believe long term this would enable us to create more complex app with a more clearly defined controlplane.

Right now, I am starting to have a slightly different way to see the distributed state. I think the state should stay in the backend and acts to orchestrate the data plane, but the API should acts as the controlplane and enable modifying the state to start works or fetch data from a persistent database.

Best, T.C

tchaton avatar Aug 02 '22 11:08 tchaton