Skip to content

Commit b1ad015

Browse files
authored
Merge pull request #214 from labthings/rename-endpoint
Rename fastapi_endpoint to endpoint
2 parents 69a1551 + 3af0bfd commit b1ad015

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/labthings_fastapi/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from .thing_server_interface import ThingServerInterface
2525
from .properties import property, setting, DataProperty, DataSetting
2626
from .actions import action
27-
from .endpoints import fastapi_endpoint
27+
from .endpoints import endpoint
2828
from . import deps
2929
from . import outputs
3030
from .outputs import blob
@@ -52,7 +52,7 @@
5252
"DataSetting",
5353
"action",
5454
"thing_slot",
55-
"fastapi_endpoint",
55+
"endpoint",
5656
"deps",
5757
"outputs",
5858
"blob",

src/labthings_fastapi/endpoints.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
arguments through to the relevant `fastapi` decorator.
1010
1111
This will most usually be applied as a decorator with arguments, available
12-
as :deco:`.fastapi_endpoint`. See the documentation for that function for
12+
as :deco:`.endpoint`. See the documentation for that function for
1313
more detail.
1414
"""
1515

@@ -34,7 +34,7 @@
3434
from .thing import Thing
3535

3636
HTTPMethod = Literal["get", "post", "put", "delete"]
37-
"""Valid HTTP verbs to use with `.fastapi_endpoint` or `.EndpointDescriptor`."""
37+
"""Valid HTTP verbs to use with `.endpoint` or `.EndpointDescriptor`."""
3838

3939

4040
class EndpointDescriptor(BaseDescriptor):
@@ -49,7 +49,7 @@ def __init__(
4949
) -> None:
5050
r"""Initialise an EndpointDescriptor.
5151
52-
See `.fastapi_endpoint`, which is the usual way of instantiating this
52+
See `.endpoint`, which is the usual way of instantiating this
5353
class.
5454
5555
:param func: is the method (defined on a `.Thing`) wrapped by this
@@ -107,19 +107,19 @@ def add_to_fastapi(self, app: FastAPI, thing: Thing) -> None:
107107
"path set on the Thing. This usually means it is not connected "
108108
"to a ThingServer."
109109
)
110-
# fastapi_endpoint is equivalent to app.get/app.post/whatever
111-
fastapi_endpoint = getattr(app, self.http_method)
110+
# endpoint is equivalent to app.get/app.post/whatever
111+
endpoint = getattr(app, self.http_method)
112112
bound_function = partial(self.func, thing)
113113
# NB the line above can't use self.__get__ as wraps() confuses FastAPI
114114
kwargs: dict[str, Any] = { # Auto-populate description and summary
115115
"description": f"## {self.title}\n\n {self.description}",
116116
"summary": self.title,
117117
}
118118
kwargs.update(self.kwargs)
119-
fastapi_endpoint(thing.path + self.path, **kwargs)(bound_function)
119+
endpoint(thing.path + self.path, **kwargs)(bound_function)
120120

121121

122-
def fastapi_endpoint(
122+
def endpoint(
123123
method: HTTPMethod, path: Optional[str] = None, **kwargs: Any
124124
) -> Callable[[Callable], EndpointDescriptor]:
125125
r"""Mark a function as a FastAPI endpoint without making it an action.
@@ -140,7 +140,7 @@ def fastapi_endpoint(
140140
.. code-block:: python
141141
142142
class DownloadThing(Thing):
143-
@fastapi_endpoint("get")
143+
@endpoint("get")
144144
def plain_text_response(self) -> str:
145145
return "example string"
146146

tests/test_endpoint_decorator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ class PostBodyModel(BaseModel):
99

1010

1111
class MyThing(lt.Thing):
12-
@lt.fastapi_endpoint("get")
12+
@lt.endpoint("get")
1313
def path_from_name(self) -> str:
1414
return "path_from_name"
1515

16-
@lt.fastapi_endpoint("get", path="path_from_path")
16+
@lt.endpoint("get", path="path_from_path")
1717
def get_method(self) -> str:
1818
return "get_method"
1919

20-
@lt.fastapi_endpoint("post", path="path_from_path")
20+
@lt.endpoint("post", path="path_from_path")
2121
def post_method(self, body: PostBodyModel) -> str:
2222
return f"post_method {body.a} {body.b}"
2323

0 commit comments

Comments
 (0)