An endpoint is a network-accessible address where a service receives requests and returns responses. In REST, endpoints commonly represent resources such as customer collections, individual customers, or sub-resources. section 9.1.1
A REST API can expose related endpoints at different levels:
- customers returns a customer collection, potentially paginated. section 9.1.1
- customers/1 identifies one customer by its integer ID. section 9.1.1
- customers/1/favorites addresses a customer's favorite-products sub-resource. section 9.1.1
A time endpoint
With aiohttp, @routes.get('/time') connects an HTTP GET request to a coroutine. The coroutine builds month, day, and time data, then returns a JSON response with status 200 and an application/json content type. Running the application makes the endpoint available at localhost:8080/time for a browser or cURL. section 9.1.2
Listing 9.1 The current time endpoint
from aiohttp import web
from datetime import datetime
from aiohttp.web_request import Request
from aiohttp.web_response import Response
routes = web.RouteTableDef()
@routes.get('/time') #1
async def time(request: Request) -> Response:
today = datetime.today()
result = {
'month': today.month,
'day': today.day,
'time': str(today.time())
}
return web.json_response(result) #2
app = web.Application() #3
app.add_routes(routes)
web.run_app(app)
Use the runnable listing to see route declaration, request handling, JSON serialization, application registration, and server startup together. section 9.1.2

























