issue_comments: 1499491258
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | issue | performed_via_github_app |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/simonw/datasette/issues/2054#issuecomment-1499491258 | https://api.github.com/repos/simonw/datasette/issues/2054 | 1499491258 | IC_kwDOBm6k_c5ZYGu6 | 9599 | 2023-04-06T19:00:16Z | 2023-04-06T20:40:16Z | OWNER | I asked GPT-4 to compare URL routing based on path and verb approaches in different languages and frameworks and spit out some examples. Full transcript here: https://gist.github.com/simonw/fa2379b97420404a81b0fcdb4db79657 Initial prompt:
Flask: ```python from flask import Flask app = Flask(name) @app.route('/example', methods=['GET']) def get_example(): return "This is a GET request." @app.route('/example', methods=['POST']) def post_example(): return "This is a POST request." if name == 'main':
app.run()
app.get('/example', (req, res) => { res.send('This is a GET request.'); }); app.post('/example', (req, res) => { res.send('This is a POST request.'); }); app.listen(3000, () => {
console.log('Server is running on port 3000');
});
import ( "github.com/gin-gonic/gin" ) func main() { r := gin.Default()
}
async fn get_example() -> impl Responder { HttpResponse::Ok().body("This is a GET request.") } async fn post_example() -> impl Responder { HttpResponse::Ok().body("This is a POST request.") } [actix_web::main]async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.route("/example", web::get().to(get_example))
.route("/example", web::post().to(post_example))
})
.bind("127.0.0.1:8080")?
.run()
.await
}
const app = new Koa(); const router = new Router(); router.get('/example', (ctx) => { ctx.body = 'This is a GET request.'; }); router.post('/example', (ctx) => { ctx.body = 'This is a POST request.'; }); app.use(router.routes()); app.use(router.allowedMethods()); app.listen(3000, () => {
console.log('Server is running on port 3000');
});
class ExampleView(View): def get(self, request): return HttpResponse("This is a GET request.")
urlpatterns = [
path('example/', ExampleView.as_view(), name='example'),
]
![feature(proc_macro_hygiene, decl_macro)][macro_use] extern crate rocket;use rocket::response::content; [get("/example")]fn get_example() -> content::Plain<&'static str> { content::Plain("This is a GET request.") } [post("/example")]fn post_example() -> content::Plain<&'static str> { content::Plain("This is a POST request.") } [launch]fn rocket() -> _ {
rocket::build().mount("/", routes![get_example, post_example])
}
pipeline :api do plug :accepts, ["json"] end scope "/api", ExampleAppWeb do pipe_through :api
end
end
app = Bottle() @app.route('/example', method='GET') def get_example(): return "This is a GET request." @app.route('/example', method='POST') def post_example(): return "This is a POST request." if name == 'main':
run(app, host='localhost', port=8080)
app = FastAPI() @app.get("/example") async def get_example(): return {"message": "This is a GET request."} @app.post("/example") async def post_example(): return {"message": "This is a POST request."} if name == "main": import uvicorn uvicorn.run(app, host="127.0.0.1", port=8000) ``` |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
1657861026 |