Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 43 commits into from
Aug 11, 2022

Conversation

tchaton
Copy link
Contributor

@tchaton tchaton commented Jul 31, 2022

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

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • 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)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • 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:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • 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 🙃

cc @Borda

@github-actions github-actions bot added the app (removed) Generic label for Lightning App package label Jul 31, 2022
@tchaton tchaton marked this pull request as draft July 31, 2022 11:06
@tchaton tchaton marked this pull request as ready for review July 31, 2022 19:36
@tchaton tchaton changed the title Introduce configure_api Introduce configure_api and Post, Get, Delete, Put Protocol Jul 31, 2022
@tchaton tchaton self-assigned this Jul 31, 2022
@tchaton tchaton added this to the app:0.6 milestone Jul 31, 2022
@tchaton tchaton changed the title Introduce configure_api and Post, Get, Delete, Put Protocol (app) Introduce configure_api and Post, Get, Delete, Put Protocol Jul 31, 2022
@tchaton tchaton changed the title (app) Introduce configure_api and Post, Get, Delete, Put Protocol (app) Introduce configure_api and Post, Get, Delete, Put HttpMethods Jul 31, 2022
@tchaton tchaton requested a review from lantiga July 31, 2022 20:31
Copy link
Contributor

@hhsecond hhsecond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tchaton can you add a valid use case for this feature (that you cannot accomplish with configure_route) in the PR description please (perhaps we could port the same over to the doc as well)?

@tchaton
Copy link
Contributor Author

tchaton commented Aug 2, 2022

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

Copy link
Collaborator

@lantiga lantiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just a few comments

src/lightning_app/api/http_methods.py Outdated Show resolved Hide resolved
examples/app_commands_and_api/app.py Outdated Show resolved Hide resolved
src/lightning_app/core/api.py Outdated Show resolved Hide resolved
src/lightning_app/core/api.py Outdated Show resolved Hide resolved
src/lightning_app/core/api.py Show resolved Hide resolved
tests/tests_app_examples/test_commands_and_api.py Outdated Show resolved Hide resolved
@mergify mergify bot removed the has conflicts label Aug 11, 2022
@tchaton tchaton requested review from lantiga and manskx August 11, 2022 08:42
@mergify mergify bot added the ready PRs ready to be merged label Aug 11, 2022
Copy link
Collaborator

@lantiga lantiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tchaton tchaton enabled auto-merge (squash) August 11, 2022 09:14
@tchaton tchaton disabled auto-merge August 11, 2022 09:21
@tchaton tchaton enabled auto-merge (squash) August 11, 2022 09:39
Copy link
Member

@ethanwharris ethanwharris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tiny comments

src/lightning_app/api/http_methods.py Outdated Show resolved Hide resolved
src/lightning_app/core/flow.py Outdated Show resolved Hide resolved
@tchaton tchaton disabled auto-merge August 11, 2022 10:04
@tchaton tchaton enabled auto-merge (squash) August 11, 2022 10:07
@tchaton tchaton merged commit 6eed72b into master Aug 11, 2022
@tchaton tchaton deleted the add_configure_api branch August 11, 2022 10:35
@Borda Borda modified the milestones: app:0.7, app:0.6 Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app (removed) Generic label for Lightning App package ready PRs ready to be merged
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants