Skip to content

Commit 9cf122f

Browse files
authored
feat: add method to get api details (#90)
2 parents 0a515a1 + eb03a1d commit 9cf122f

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

nitric/resources/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
"""Nitric Python SDK API Documentation. See: https://nitric.io/docs?lang=python for full framework documentation."""
2020

21-
from nitric.resources.apis import Api, api, MethodOptions, ApiOptions, JwtSecurityDefinition
21+
from nitric.resources.apis import Api, api, MethodOptions, ApiOptions, ApiDetails, JwtSecurityDefinition
2222
from nitric.resources.buckets import Bucket, bucket
2323
from nitric.resources.collections import Collection, collection
2424
from nitric.resources.queues import Queue, queue
@@ -30,6 +30,7 @@
3030
"api",
3131
"Api",
3232
"ApiOptions",
33+
"ApiDetails",
3334
"JwtSecurityDefinition",
3435
"MethodOptions",
3536
"bucket",

nitric/resources/apis.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,26 @@
3030
ApiSecurityDefinition,
3131
ApiSecurityDefinitionJwt,
3232
ResourceDeclareRequest,
33+
ResourceDetailsRequest,
3334
)
3435
from grpclib import GRPCError
3536
from nitric.api.exception import exception_from_grpc_error
3637

3738

39+
@dataclass
40+
class ApiDetails:
41+
"""Represents the APIs deployment details."""
42+
43+
# the identifier of the resource
44+
id: str
45+
# The provider this resource is deployed with (e.g. aws)
46+
provider: str
47+
# The service this resource is deployed on (e.g. ApiGateway)
48+
service: str
49+
# The url of the API
50+
url: str
51+
52+
3853
@dataclass
3954
class JwtSecurityDefinition:
4055
"""Represents the JWT security definition for an API."""
@@ -248,6 +263,23 @@ def decorator(function: HttpMiddleware):
248263

249264
return decorator
250265

266+
async def _details(self) -> ApiDetails:
267+
"""Get the API deployment details."""
268+
try:
269+
res = await self._resources_stub.details(
270+
resource_details_request=ResourceDetailsRequest(
271+
resource=_to_resource(self),
272+
)
273+
)
274+
return ApiDetails(res.id, res.provider, res.service, res.api.url)
275+
except GRPCError as grpc_err:
276+
raise exception_from_grpc_error(grpc_err)
277+
278+
async def URL(self) -> str:
279+
"""Get the APIs live URL."""
280+
details = await self._details()
281+
return details.url
282+
251283

252284
class Route:
253285
"""An HTTP route."""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_current_version_tag():
4242
],
4343
setup_requires=["wheel"],
4444
install_requires=[
45-
"nitric-api==0.18.0",
45+
"nitric-api==0.21.0",
4646
"protobuf==3.19.4",
4747
"asyncio",
4848
],

0 commit comments

Comments
 (0)