投稿時間:2023-03-28 11:27:32 RSSフィード2023-03-28 11:00 分まとめ(29件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT 気になる、記になる… Anker、ワイヤレス充電パット内蔵のPCスタンド一体型ドック「Anker 675 USB-C ドッキングステーション (12-in-1, Monitor Stand, Wireless)」を発売 https://taisy0.com/2023/03/28/169999.html inmonitorstandw 2023-03-28 02:00:00
IT 気になる、記になる… Apple、「iPhone」の整備済み品を国内でも販売開始 https://taisy0.com/2023/03/28/170076.html apple 2023-03-28 01:22:44
ROBOT ロボスタ アクセルとティアフォーが完全⾃動運転に特化したシステムオンチップ(LSI)の試作品を完成 2023年3月末から実証実験を開始 https://robotstart.info/2023/03/28/axell-tear4-lsi.html 2023-03-28 01:18:32
IT ITmedia 総合記事一覧 [ITmedia News] メルカリ、LLM・生成AI専門チーム立ち上げ 自社のさまざまなデータ活用 https://www.itmedia.co.jp/news/articles/2303/28/news093.html itmedia 2023-03-28 10:47:00
IT ITmedia 総合記事一覧 [ITmedia News] Microsoft、「Teams」のデスクトップ版を刷新 「使用メモリ半減、性能2倍」 生成型AIも使いやすく https://www.itmedia.co.jp/news/articles/2303/28/news092.html itmedianewsmicrosoft 2023-03-28 10:41:00
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] 金融の勉強、3割「経験あり」 勉強を始めるハードルは? https://www.itmedia.co.jp/business/articles/2303/28/news077.html itmedia 2023-03-28 10:35:00
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] 「乃が美」と「いきなり!ステーキ」の共通点は何か 両社がハマった沼 https://www.itmedia.co.jp/business/articles/2303/27/news209.html itmedia 2023-03-28 10:25:00
TECH Techable(テッカブル) シニアの孤独解消に。高齢者向けサービス「あのね」でコミュニケーションロボットを導入 https://techable.jp/archives/201725 boccoemo 2023-03-28 01:05:31
python Pythonタグが付けられた新着投稿 - Qiita mysqlclientがインストールできない!!!なんで!!! https://qiita.com/mmmm7064/items/b12ecd77a52ed2e09f5e pythonmve 2023-03-28 10:41:38
js JavaScriptタグが付けられた新着投稿 - Qiita 無料でFirebaseを始めてNoSQLデータベースを作成してクライアント側からアクセスしよう https://qiita.com/asameshiCode/items/a6039e0715951576e19c asameshicodecom 2023-03-28 10:48:46
js JavaScriptタグが付けられた新着投稿 - Qiita React + TypeScript: スナップショットとしての状態 https://qiita.com/FumioNonaka/items/de813331817014bac2e6 introducingreactdev 2023-03-28 10:38:48
Ruby Rubyタグが付けられた新着投稿 - Qiita Ruby で正規表現の連結(連接、concatenation) https://qiita.com/yuinore/items/8313246589a5ac3cefb1 concatenation 2023-03-28 10:44:56
Linux Ubuntuタグが付けられた新着投稿 - Qiita mysqlclientがインストールできない!!!なんで!!! https://qiita.com/mmmm7064/items/b12ecd77a52ed2e09f5e pythonmve 2023-03-28 10:41:38
Ruby Railsタグが付けられた新着投稿 - Qiita Rails初心者が基本を確認する為の10の質問 https://qiita.com/yukisakakima/items/73ddfceecff167180191 rails 2023-03-28 11:00:01
技術ブログ Developers.IO AWSのコストを削減したい方必見!無料で使える運用ツールのご紹介 https://dev.classmethod.jp/articles/aws_usage_cost_reduction/ opswitch 2023-03-28 01:35:12
技術ブログ Yahoo! JAPAN Tech Blog 2023年4月の技術&デザイン系イベント予定 https://techblog.yahoo.co.jp/entry/2023032830418739/?cpt_n=BlogFeed&cpt_m=lnk&cpt_s=rss 技術 2023-03-28 11:00:00
海外TECH DEV Community How to build an API using Flask https://dev.to/onecuriousmindset/how-to-build-an-api-using-flask-43ke How to build an API using FlaskIn this tutorial we will learn how to create a simple RESTful API using Flask a lightweight web framework for Python We will also use SQLAlchemy an ORM Object Relational Mapper that allows us to interact with a database using Python objects We will use SQLite as our database but you can use any other database that SQLAlchemy supports What is a RESTful API A RESTful API Representational State Transfer is a way of designing web services that follow some principles Each resource such as a user a product a post etc is identified by a unique URI Uniform Resource Identifier such as users or products The client can perform different operations on the resources using HTTP methods such as GET POST PUT PATCH DELETE etc For example to create a new user the client can send a POST request to users with the user data in the request body To update an existing user the client can send a PUT or PATCH request to users with the updated data in the request body To delete a user the client can send a DELETE request to users The server responds with the appropriate status code and data in the response body usually in JSON JavaScript Object Notation format For example if the user creation was successful the server can respond with a Created status code and the created user data in the response body If the user update was successful the server can respond with a OK status code and the updated user data in the response body If the user deletion was successful the server can respond with a No Content status code and no response body What is Flask Flask is a micro web framework for Python that allows us to create web applications quickly and easily It has minimal dependencies and provides us with the essential tools to build web services such as routing request and response handling templating etc Flask is also extensible and supports various extensions that add more functionality to our applications such as SQLAlchemy for database integration Flask RESTful for building RESTful APIs Flask JWT for authentication and authorization etc What is SQLAlchemy SQLAlchemy is an ORM that allows us to work with databases using Python objects It abstracts away the low level details of SQL queries and provides us with a high level interface to manipulate data SQLAlchemy supports various databases such as SQLite PostgreSQL MySQL Oracle etc SQLAlchemy also provides us with declarative models that define our database schema using Python classes and attributes We can then use these models to perform CRUD Create Read Update Delete operations on our data Setting up our project To start our project we need to install some dependencies Python You can download it from or use your preferred package manager Pip A tool for installing Python packages It should come with Python by default Virtualenv A tool for creating isolated Python environments You can install it using pip install virtualenv Flask Our web framework You can install it using pip install flask SQLAlchemy Our ORM You can install it using pip install sqlalchemy Flask SQLAlchemy An extension that integrates SQLAlchemy with Flask You can install it using pip install flask sqlalchemy Next we need to create our project directory and files Create a directory called flask api and navigate to it Create a virtual environment called venv using virtualenv venv Activate the virtual environment using source venv bin activate on Linux Mac or venv Scripts activate on Windows Create a file called app py that will contain our main application code Create a file called models py that will contain our database models Create a file called config py that will contain our configuration settings Configuring our applicationIn our config py file we need to define some configuration settings for our application import os Get the absolute path of the current directorybasedir os path abspath os path dirname file Define the SQLALCHEMY DATABASE URI variable that tells SQLAlchemy where to find our database We will use SQLite for simplicity and store it in a file called app db in our project directorySQLALCHEMY DATABASE URI sqlite os path join basedir app db Define the SQLALCHEMY TRACK MODIFICATIONS variable that tells SQLAlchemy whether to track changes to the database We will set it to False to avoid unnecessary overheadSQLALCHEMY TRACK MODIFICATIONS False Creating our applicationIn our app py file we need to create our Flask application and initialize it with our configuration settings To interact with the database using SQLAlchemy we need to create a db object and associate it with our Flask application This can be achieved by importing the SQLAlchemy class from the flask sqlalchemy module and creating a db object in a separate file called db py Here is an example code snippet for creating the db object from flask sqlalchemy import SQLAlchemy Create a SQLAlchemy objectdb SQLAlchemy Then in the main application file app py we can create a Flask application and associate it with the db object by calling the init app method of the db object Here is an example code snippet from flask import Flaskfrom db import db Create a Flask application with the name of the current moduleapp Flask name Load the configuration settings from the config py fileapp config from pyfile config py Initialize the SQLAlchemy object with our applicationdb init app app Defining our database modelsIn our models py file we need to define our database models using SQLAlchemy s declarative syntax A model is a Python class that represents a table in our database and its attributes represent the columns We also need to import the db object which we will use to interact with our database For this tutorial we will create a simple model called User that has the following attributes id An integer that is the primary key of the table and uniquely identifies each user name A string that stores the name of the user email A string that stores the email address of the user Now we can define our model as follows from db import db Define a User model that inherits from db Modelclass User db Model Define the id attribute as an integer column that is the primary key id db Column db Integer primary key True Define the name attribute as a string column that is not nullable name db Column db String nullable False Define the email attribute as a string column that is unique and not nullable email db Column db String unique True nullable False Define a repr method that returns a string representation of the user object def repr self return f lt User self name gt Creating our databaseAfter defining our database model the next step is to create the actual database and its tables This can be done using SQLAlchemy s create all method To do this we ll first need to activate our virtual environment if it isn t already and then create a file called create db py Inside create db py we ll include the following code snippet from app import app db Create and push an application contextwith app app context Now you can use the db object db create all Execute the file in the terminal We can verify that our database and its tables have been created by looking at the app db file in our project directory We can also use a tool like DB Browser for SQLite to inspect and manipulate our database Building Our APINow that we have created our database and its model we can start building our API We will use Flask s built in routing system to define different endpoints for our API and handle different HTTP methods We will also use Flask s request and jsonify functions to parse and return JSON data We will implement the following endpoints for our API GET users Return a list of all users in JSON format GET users lt id gt Return a single user with the given id in JSON format If no user with that id exists return a Not Found error POST users Create a new user with the data provided in the request body in JSON format Return the created user in JSON format with a Created status code PUT users lt id gt Update an existing user with the given id with the data provided in the request body in JSON format Return the updated user in JSON format with a OK status code If no user with that id exists return a Not Found error DELETE users lt id gt Delete an existing user with the given id Return a No Content status code If no user with that id exists return a Not Found error We can add the following code to our app py file to implement these endpoints from flask import Flask jsonify requestfrom db import db Create a Flask application with the name of the current moduleapp Flask name Load the configuration settings from the config py fileapp config from pyfile config py Initialize the SQLAlchemy object with our applicationdb init app app Import the User model from models pyfrom models import User Define a route for the GET users endpoint app route users methods GET def get users Query all users from the database users User query all Convert each user object to a dictionary users dict user dict for user in users Remove the sa instance state attribute from each dictionary for user dict in users dict user dict pop sa instance state Return a JSON response with the list of users return jsonify users dict Define a route for the GET users lt id gt endpoint app route users lt int id gt methods GET def get user id Query a user by id from the database user User query get id Check if the user exists if user is None Return a error if not found return jsonify message User not found else Convert the user object to a dictionary user dict user dict Remove the sa instance state attribute from the dictionary user dict pop sa instance state Return a JSON response with the user data return jsonify user dict Define a route for the POST users endpoint app route users methods POST def create user Get the data from the request body as a dictionary data request get json Check if the data is valid if name not in data or email not in data Return a error if missing name or email return jsonify message Name and email are required else Create a new user object with the data user User name data name email data email Add and commit the user to the database db session add user db session commit Convert the user object to a dictionary user dict user dict Remove the sa instance state attribute from the dictionary user dict pop sa instance state Return a JSON response with the created user data and a status code return jsonify user dict Define a route for the PUT users lt id gt endpoint app route users lt int id gt methods PUT def update user id Query a user by id from the database user User query get id Check if the user exists if user is None Return a error if not found return jsonify message User not found else Get the data from the request body as a dictionary data request get json Check if the data is valid if name not in data or email not in data Return a error if missing name or email return jsonify message Name and email are required else Update the user object with the data user name data name user email data email Commit the changes to the database db session commit Convert the user object to a dictionary user dict user dict Remove the sa instance state attribute from the dictionary user dict pop sa instance state Return a JSON response with the updated user data and a status code return jsonify user dict Define a route for the DELETE users lt id gt endpoint app route users lt int id gt methods DELETE def delete user id Query a user by id from the database user User query get id Check if the user exists if user is None Return a error if not found return jsonify message User not found else Delete the user from the database db session delete user db session commit Return a status code with no response body return if name main app run Testing our APINow that we have implemented our API endpoints we can test them using a tool like Postman or curl We can use these tools to send different HTTP requests to our API and inspect the responses To test our API we need to do the following steps Run our Flask application using python app py Open Postman or curl and send different requests to our API endpoints Check the status codes and response bodies of each request First let s create new users using POST method POST users Create a new user with the data provided in the request body in JSON format Return the created user in JSON format with a Created status code Request User curl X POST H Content Type application json d name Alice email alice example com usersResponse User curl X POST H Content Type application json d name Bob email bob example com usersUser curl X POST H Content Type application json d name Charlie email charlie example com usersNow we will use GET method to return the list of users in JSON format GET users Request curl usersResponse id name Alice email alice example com id name Bob email bob example com id name Charlie email charlie example com GET users lt id gt Return a single user with the given id in JSON format If no user with that id exists return a Not Found error Request curl http localhost users Response id name Alice email alice example com Request curl http localhost users Response message User not found PUT users lt id gt Update an existing user with the given id with the data provided in the request body in JSON format Return the updated user in JSON format with a OK status code If no user with that id exists return a Not Found error Request curl X PUT H Content Type application json d name Alice email alice new com http localhost users Response Use GET to check the updated details of the usercurl http localhost users Response id name Alice email alice new com Request curl X PUT H Content Type application json d name Eve email eve example com http localhost users Response message User not found DELETE users lt id gt Delete an existing user with the given id Return a No Content status code If no user with that id exists return a Not Found error Request curl X DELETE http localhost users Response No response body Request curl X DELETE http localhost users Response message User not found To sum up in this tutorial we have learned how to create a simple RESTful API using Flask and SQLAlchemy We have also learned how to perform CRUD operations on our database using Python objects and how to test our API using curl Flask and Flask RESTful provide many advanced features and options for building REST APIs such as connecting to databases using flask sqlalchemy serialization and deserialization of data using flask marshmallow adding authentication and authorization using flask jwt extended and generating interactive documentation for the API using flask swagger ui Flask DocumentationFlask RESTful DocumentationFor more information and examples you can refer to the official documentation of Flask and Flask RESTful available at I hope you enjoyed this tutorial and found it useful Happy coding 2023-03-28 01:24:51
海外科学 NYT > Science La melena de Beethoven revela secretos médicos y familiares https://www.nytimes.com/es/2023/03/23/espanol/beethoven-adn-pelo.html La melena de Beethoven revela secretos médicos y familiaresEl análisis de siete muestras de pelo del venerado compositor permitióa los investigadores desmentir mitos y plantear nuevas preguntas sobre su vida y su muerte 2023-03-28 01:45:35
金融 日本銀行:RSS 金融システムレポート別冊「地域金融機関の気候変動対応の現状」 http://www.boj.or.jp/research/brp/fsr/fsrb230328.htm 気候変動 2023-03-28 11:00:00
ビジネス ダイヤモンド・オンライン - 新着記事 仮想通貨企業との取引に意欲、米地銀や新興銀行 - WSJ発 https://diamond.jp/articles/-/320275 仮想通貨 2023-03-28 10:15:00
GCP Google Cloud Platform Japan 公式ブログ ベイシア:BigQuery や Dataplex を活用しデータ分析基盤を刷新、パフォーマンスや運用効率の課題を改善 https://cloud.google.com/blog/ja/topics/customers/beisia-data-analytics-infrastructure-with-bigquery-and-dataplex/ ベイシアBigQueryやDataplexを活用しデータ分析基盤を刷新、パフォーマンスや運用効率の課題を改善全国店舗年月末現在を展開するショッピングセンターチェーン「ベイシア」を運営する株式会社ベイシア以下、ベイシアがデータ分析基盤を刷新し、そのプラットフォームにGoogleCloudを採用しました。 2023-03-28 02:00:00
ビジネス 東洋経済オンライン 「脱・経済成長」と気軽に言う人は正直ズレている 絶対的貧困層をどうやって救うつもりなのか | リーダーシップ・教養・資格・スキル | 東洋経済オンライン https://toyokeizai.net/articles/-/660406?utm_source=rss&utm_medium=http&utm_campaign=link_back 世界銀行 2023-03-28 10:30:00
ビジネス プレジデントオンライン 日常の慢性的なストレスによってもトラウマは生じる…人間が想定外のストレスに弱いメカニズム - 異動、結婚、引っ越し、子供どもの受験…日常に潜む意外なリスク https://president.jp/articles/-/67951 公認心理師 2023-03-28 11:00:00
ビジネス プレジデントオンライン 参加国わずか28…WBC=野球"オワコン化"で盛り上がるのは侍ジャパン優勝の日本だけという皮肉な現実 - アメリカでのMLB人気はNFLやNBAに遠く及ばない https://president.jp/articles/-/67854 侍ジャパン 2023-03-28 11:00:00
ビジネス プレジデントオンライン 「4~6時間台のランナーが絶対履いてはいけない厚底」下手すると股関節周りの骨折やケガに泣くハメになる - ナイキ×アシックスのシューズ戦争が生んだゆっくり市民ランナー向けとは https://president.jp/articles/-/67823 箱根駅伝 2023-03-28 11:00:00
ビジネス プレジデントオンライン 日常の慢性的なストレスによってもトラウマは生じる…人間が想定外のストレスに弱いメカニズム - 異動、結婚、引っ越し、子供どもの受験…日常に潜む意外なリスク https://president.jp/articles/-/67729 公認心理師 2023-03-28 11:00:00
IT 週刊アスキー フリープランのストレージ容量を賢く使う工夫3選 https://weekly.ascii.jp/elem/000/004/129/4129229/ lineworks 2023-03-28 10:30:00
マーケティング AdverTimes AIは色を〈理解〉しているか? アートディレクターが「ChatGPT」に配色を提案させてみた https://www.advertimes.com/20230328/article414692/ chatgpt 2023-03-28 01:39:26
GCP Cloud Blog JA ベイシア:BigQuery や Dataplex を活用しデータ分析基盤を刷新、パフォーマンスや運用効率の課題を改善 https://cloud.google.com/blog/ja/topics/customers/beisia-data-analytics-infrastructure-with-bigquery-and-dataplex/ ベイシアBigQueryやDataplexを活用しデータ分析基盤を刷新、パフォーマンスや運用効率の課題を改善全国店舗年月末現在を展開するショッピングセンターチェーン「ベイシア」を運営する株式会社ベイシア以下、ベイシアがデータ分析基盤を刷新し、そのプラットフォームにGoogleCloudを採用しました。 2023-03-28 02:00:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)