{"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675889865", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675889865, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTg4OTg2NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-19T06:57:00Z", "updated_at": "2020-08-19T06:57:00Z", "author_association": "OWNER", "body": "Maybe `.get` vs `.get_html`?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675889551", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675889551, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTg4OTU1MQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-19T06:56:06Z", "updated_at": "2020-08-19T06:56:17Z", "author_association": "OWNER", "body": "I'm leaning towards defaulting to JSON as the requested format - you can pass `format=\"html\"` if you want HTML.\r\n\r\nBut weird that it's different from the web UI.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675884980", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675884980, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTg4NDk4MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-19T06:44:26Z", "updated_at": "2020-08-19T06:44:26Z", "author_association": "OWNER", "body": "Need to decide what to do about JSON responses.\r\n\r\nWhen called from a template it's likely the intent will be to further loop through the JSON data returned. It would be annoying to have to run `json.loads` here.\r\n\r\nMaybe a `.get_json()` method then? Or even return a response that has `.json()` and `.text` similar to `httpx` - or just return an `httpx` response.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675788203", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675788203, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTc4ODIwMw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-19T00:46:08Z", "updated_at": "2020-08-19T00:46:23Z", "author_association": "OWNER", "body": "Also fun: the inevitable plugin that exposes this to the template language - so Datasette templates can stitch together data from multiple other internal API calls. Fun way to take advantage of `async` support in Jinja.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675787416", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675787416, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTc4NzQxNg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-19T00:42:38Z", "updated_at": "2020-08-19T00:42:38Z", "author_association": "OWNER", "body": "I just realised that this mechanism is kind of like being able to use microservices - make API calls within your application - except that everything runs in the same process against SQLite databases so calls will be _lightning fast_.\r\n\r\nIt also means that a plugin can add a new internal API to Datasette that's accessible to other plugins by registering a new route with `register_routes`!", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675753114", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675753114, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTc1MzExNA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-18T22:34:55Z", "updated_at": "2020-08-18T22:34:55Z", "author_association": "OWNER", "body": "Maybe allow this:\r\n\r\n response = await datasette.get(\"/{database}/{table}.json\", database=database, table=table)\r\n\r\nThis could cause problems if users ever need to pass literal `{` in their paths. Maybe allow this too:\r\n\r\n response = await datasette.get(\"/{database}/{table}.json\", interpolate=False)\r\n\r\nNot convinced this is useful - it's a bit unintuitive.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675752436", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675752436, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTc1MjQzNg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-18T22:32:44Z", "updated_at": "2020-08-18T22:32:44Z", "author_association": "OWNER", "body": "One thing to consider here: Datasette's table and database name escaping rules can be a little bit convoluted.\r\n\r\nIf a plugin wants to get back the first five rows of a table, it will need to construct a URL `/dbname/tablename?_size=5` - but it will need to know how to turn the database and table names into the correctly escaped `dbname` and `tablename` values.\r\n\r\nHere's how the `row.html` table handles that right now: https://github.com/simonw/datasette/blob/b21ed237ab940768574c834aa5a7130724bd3a2d/datasette/templates/row.html#L19-L23\r\n\r\nIt would be an improvement to have this logic abstracted out somewhere and documented so plugins can use it.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675751719", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675751719, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTc1MTcxOQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-18T22:30:27Z", "updated_at": "2020-08-18T22:30:27Z", "author_association": "OWNER", "body": "Right now calling `datasette.app()` instantiates an ASGI application - complete with a bunch of routes and wrappers - and returns that application object. Calling it twice instantiates another ASGI application.\r\n\r\nI think a single `Datasette` instance should only ever create a single ASGI app - so the `.app()` method should cache the ASGI app that it returns the first time and return the same application again on future calls.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675750845", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675750845, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTc1MDg0NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-18T22:27:43Z", "updated_at": "2020-08-18T22:27:43Z", "author_association": "OWNER", "body": "What about authentication checks etc? Won't they run twice?\r\n\r\nI think that's OK too, in fact it's desirable: think of the case of `datasette-graphql` where a bunch of different TableView calls are being made as part of the same GraphQL queries. Having those calls take advantage of finely grained per-table authentication and permission checks seems like a good feature.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675750382", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675750382, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTc1MDM4Mg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-18T22:26:15Z", "updated_at": "2020-08-18T22:26:15Z", "author_association": "OWNER", "body": "Should internal requests executed in this way be handled by plugins that used the `asgi_wrapper()` hook?\r\n\r\nHard to be sure one way or the other. I'm worried about logging middleware triggering twice - but actually anyone doing serious logging of their Datasette instance is probably doing it in a different layer (uvicorn logs or nginx proxy or whatever) so they wouldn't be affected. There aren't any ASGI logging middlewares out there that I've seen.\r\n\r\nAlso: if you run into a situation where your stuff is breaking because `datasette.get()` is calling ASGI middleware twice you can fix it by running your ASGI middleware outside of the `asgi_wrapper` plugin hook mechanism.\r\n\r\nSo I think it DOES execute `asgi_wrapper()` middleware.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675749319", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675749319, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTc0OTMxOQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-18T22:23:01Z", "updated_at": "2020-08-18T22:23:01Z", "author_association": "OWNER", "body": "Actually no - `requests.get()` and `httpx.get()` prove that having a `.get()` method for an HTTP-related API isn't confusing to people at all.\r\n\r\n`datasette.get()` it is.\r\n\r\n(I'll probably add `datasette.post()` in the future too).", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675749076", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675749076, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTc0OTA3Ng==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-18T22:22:21Z", "updated_at": "2020-08-18T22:22:21Z", "author_association": "OWNER", "body": "Alternative name possibilities:\r\n\r\n- `datasette.http_get(...)` - slightly misleading since it's not going over the HTTP protocol\r\n- `datasette.internal_get(...)` - the `internal_` might suggest its not an API for external use, which isn't true - it's for plugins\r\n- `datasette.get(...)` - clashes with `dict.get()` but I'm not at all sure that's a good reason not to use it", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675748573", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675748573, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTc0ODU3Mw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-18T22:20:52Z", "updated_at": "2020-08-18T22:20:52Z", "author_association": "OWNER", "body": "Should it default to treating things as if they had the `.json` extension? There are use-cases for the non-JSON method, such as https://github.com/natbat/tidepools_near_me/commit/ec102c6da5a5d86f17628740d90b6365b671b5e1\r\n\r\nI think I'm OK with people having to add `.json` to their internal calls. Maybe they could use `format=\"json\"`) as an optional parameter which would automatically handle the very weird edge-cases where you need to use `?_format=json` instead of `.json` (due to table names existing with a `.json` suffix).", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/943#issuecomment-675747878", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/943", "id": 675747878, "node_id": "MDEyOklzc3VlQ29tbWVudDY3NTc0Nzg3OA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-08-18T22:18:46Z", "updated_at": "2020-08-18T22:19:12Z", "author_association": "OWNER", "body": "Could be as simple as `response = await datasette.get(\"/path/blah\")` - which could also be re-used by the implementation of the `datasette --get /` CLI option introduced in #927.\r\n\r\nBit weird calling it `.get()` since that clashes with Python's dictionary `.get()` method.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 681375466, "label": "await datasette.client.get(path) mechanism for executing internal requests"}, "performed_via_github_app": null}