投稿時間:2023-03-25 21:11:18 RSSフィード2023-03-25 21:00 分まとめ(14件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
python Pythonタグが付けられた新着投稿 - Qiita Zoom Webhook でvalidateを通す方法(Python) https://qiita.com/reatoretch/items/c05055ba180d2f6cff97 validate 2023-03-25 20:31:28
Ruby Rubyタグが付けられた新着投稿 - Qiita 3/25 Ruby入門remained 基礎文法編 https://qiita.com/TeihenEngineer/items/0992b53dba277f58dda1 sgreatelsifscoregtputsgo 2023-03-25 20:09:10
Linux Ubuntuタグが付けられた新着投稿 - Qiita 北陽電機製2D-LiDAR(UTM-LX-30)をROSで動かす方法 https://qiita.com/yacht0425/items/594ba89deddca9b18e34 dlidar 2023-03-25 20:59:48
Ruby Railsタグが付けられた新着投稿 - Qiita 【tableタグ】サイズ調整 https://qiita.com/ayamo/items/680035823d89d54a4fb8 lttableclasstablegtltthea 2023-03-25 20:44:51
海外TECH Ars Technica The fight to expose corporations’ real impact on the climate https://arstechnica.com/?p=1926799 carbon 2023-03-25 11:21:32
海外TECH Ars Technica Garmin’s Forerunner 955 review: Still king for runners and cyclists https://arstechnica.com/?p=1872046 athletes 2023-03-25 11:00:54
海外TECH MakeUseOf 10 Jobs That Only Exist in the Metaverse https://www.makeuseof.com/jobs-that-only-exist-in-the-metaverse/ filling 2023-03-25 11:45:16
海外TECH MakeUseOf 5 Reasons Why You Can’t Send Gifts From Your Apple Device https://www.makeuseof.com/reasons-you-cant-send-gifts-from-apple-device/ apple 2023-03-25 11:30:17
海外TECH MakeUseOf When DirecTV Stream Will Raise Its Prices (and How Much It Will Cost) https://www.makeuseof.com/directv-stream-will-raise-its-prices-how-much/ april 2023-03-25 11:15:17
海外TECH DEV Community How to use Postman for API testing https://dev.to/terieyenike/how-to-use-postman-for-api-testing-10cl How to use Postman for API testingTesting web applications is essential to check if the code written meet the criteria and standard before deployment before it reaches the user During the software development lifecycle of a product it is essential to find minor and significant issues with the app like identifying bugs within the code and fixing them promptly with the help of professionals like quality and assurance QA testers Postman is a collaborative API platform developers use to test monitor design and build their APIs with a user interface UI According to businesswire more than million developers and organizations use Postman which only shows its success as a reliable platform for API testing In this article you will learn and explore the various uses of Postman and how it can help you become productive as a developer no matter your stack Let s get started What is an API Application programming interface APIs are everywhere and it is the bedrock for how applications communicate with one another they enable integration and automation using a set of defined protocols HTTPS from the sending a request and receiving a response through a network GitHubThe complete source code for this project is in this repo PrerequisitesThe following are required to complete this tutorial Download the Postman appBasic knowledge of Node jsNode js installed on your local machine It is required for dependency installation using npm Building an API with Express jsExpress is an unopinionated web framework built on top of Node js the JavaScript runtime environment Using Express to create APIs is fast Open your terminal and run this command to create a new directory mkdir api testingNext navigate to the directory and initialize the directory with the following command cd api testingnpm init yThis command accepts all the defaults with the y flag which creates a package json file With the package json file created install these dependencies npm install expressexpress is used to create a serverThe other package to install is nodemon which would be a devDependencies That means it is only required to run during local development and testing npm install nodemon DConfigure the package json fileChange the values in the scripts section of the file with the following scripts test jest start node server js start dev nodemon server js … The script nodemon server js will automatically restart the node application when the file notices changes Note This program would not run without APIs in the index js file For this project we will use the model view controller MVC architecture pattern by dividing the application logic into three parts the Model View and Controller Let s create the server Building the modelCreate a new directory in the project s root called models and within this folder create a new file named friends model js Copy and paste the code below to create the model for our API const friends module exports friends This model contains an empty array with the declared variable friends and exported variable Building the controllerFor the controller with the same process as the model create a directory named controllers in the project s root and within the folder a new file friends controller js Copy paste the code below const model require models friends model function getFriends req res res json model function getOneFriend req res const friendId Number req params friendId const friend model friendId if friend res status json error Friend does not exist else res status json friend function postNewFriend req res if req body name return res status json error Missing friend name const newFriend name req body name id model length model push newFriend res json newFriend module exports getFriends getOneFriend postNewFriend The code snippet above does the following Import the model For the getFriends this returns the list of friends in json format The getOneFriend will return just one friend in the array using the id identifier and if the id does not exist it displays a client error The postNewFriend uses the post request method to send the data to the serverAs usual export the three functions with module exportsBuilding the routeThe API endpoint in this section will communicate with each controller using its corresponding HTTP request Create a folder called routes with a new file friends router js with each router attached to the endpoint Copy and paste this code const express require express const friendsController require controllers friends controller const friendsRouter express Router friendsRouter get friendsController getFriends friendsRouter get friendId friendsController getOneFriend friendsRouter post friendsController postNewFriend module exports friendsRouter The code above does this shows how to create a new router object using the Router functionImport the friendsController and use them in the friendsRouter to handle the requestExport the friendsRouterConnecting it allThe most important of creating or building an API server is to connect the workflow so that the MVC pattern functions to test individual endpoints First create the entry point file app js in the root directory and paste this code const express require express const app express const friendsRouter require routes friends router app use req res next gt const start Date now next const delta Date now start console log req method req baseUrl req url delta ms app get req res gt res send welcome to the friends data response app use express json app use friends friendsRouter module exports app The highlights for the code above does the following The express module is declaredRun the express function as this defines the instance of the appThe middleware app use parses the incoming JSON requests The other middleware with endpoint friends is the route attached to the hostname of the appThe GET request with the endpoint displays the message in the res send method in the browser at http localhost Export the app in the module exports classNext create the server js file in the root directory with this code const http require http const app require app const server http createServer app const PORT server listen PORT gt console log Server listening on port PORT The code above with the listen function listen to the connections on the specified port and host Let s now run the server with the command npm run start devChecking the console of your terminal it should read “Server listening on port Using Postman to test the serverCreating Postman collectionsBefore creating collections for your requests you need to create a workspace Click the Workspaces dropdown and select Create Workspace Give your workspace a name and set the visibility to Public After that click Create Workspace Let s create a new Collection in our workspace to store the requests At the left pane of the Postman window click the plus “ icon or Create Collection Next give the Collection a name Adding Requests to CollectionsTo create our first request click either the Add a request inside your new collection or the three dots icon on your Collection Next name your request “post friends Set the request method to POST and the request URL to http localhost friends which will send data to the server to create a friend Remember to hit Save Click the Body tab of the request select data type raw gt JSON and send the request by clicking the Send button Enter a name as shown below To confirm the request with the GET request method add a request named get friends with the path URL http localhost friends which will display the friends array in the response field as shown Get an individual friendAdd a request “get a friend to see the output of just one friend specifying the index included in the path URL http localhost friends with a GET request method The result of this should look like this Creating documentation for test APIsIt is essential to document your API workflow like how developers create a README md file for every GitHub project they start Similarly it is possible to do the same in Postman At the right pane of the app Select the Documentation icon Once opened you can write a detailed request description of each endpoint in your collection by clicking the pencil icon to begin ConclusionThis article taught you the basics of using Postman to test your APIs by sending requests over the network and receiving responses through the status code indicating either success or failed error status code Try Postman today and learn from its resources If you found this article helpful leave a comment Further readingPostman API documentationGet started with Node js 2023-03-25 11:27:56
海外TECH DEV Community Maximizing Your Flutter App's Performance with (Async)NotifierProvider, Freezed & Riverpod Code Generators https://dev.to/nikki_eke/maximizing-your-flutter-apps-performance-with-asyncnotifierprovider-freezed-riverpod-code-generators-1af1 Maximizing Your Flutter App x s Performance with Async NotifierProvider Freezed amp Riverpod Code GeneratorsMaximizing the performance of your Flutter app is crucial for delivering a seamless user experience As software developers we constantly seek out tools that can enhance our coding experience while improving the efficiency and quality of our code This beginner s guide focuses on utilizing the power of AsyncNotifierProvider and NotifierProvider from Riverpod together with the Riverpod code generator for efficient state management By incorporating these tools you can generate providers faster simplify the process of passing ref property around and streamline debugging The guide includes simple examples that demonstrate how to use these providers in your project and leverage the benefits of the Freezed and Riverpod code generators PrerequisitesBasic knowledge of dartA basic understanding of flutter and state management A code editor Android Studio or VScode recommended A mobile device or emulator to build on You ve read the first article in this series or have at least a basic knowledge of how Riverpod works Master Riverpod even if you are a flutter newbie Nikki Eke・Feb ・ min read flutter riverpod dart Scope of this tutorialIn this tutorial we will cover the following Examples to show the implementation of the Notifier and AsyncNotifier Providers How to use code generation tools like Freezed and Riverpod code generator How to use AsyncValue to handle loading stateHow to use copyWith when working with an immutable class Installation of DependenciesFirst you will need to get to your pubspec yaml and add the following packagesdependencies flutter riverpod riverpod annotation freezed annotation freezed dev dependencies build runner riverpod generator Then run flutter pub getYou have successfully added the necessary dependencies to your project Why use code generation tools If you choose to work without code generation tools your Riverpod providers will still be fully functional However Riverpod greatly recommends using code generation tools Code generation is using a tool to generate code In dart once you add the code generation syntax and compile your code is automatically generated Doing this saves you the time and energy you would have used to write that code especially when you are working on a big project and need to handle those tasks repeatedly Code generation will help prevent those errors that can happen when doing the same task repeatedly It makes debugging better and generally makes your life easier Freezed Code GeneratorFreezed is a code generation package that helps you create data classes with dart With the use of Freezed you can generate models unions and much more Freezed allows you to focus on the definition of your data class instead of writing long lines of code that may be error prone Read more on what you can do with Freezed Riverpod Code GeneratorWith the Riverpod code generation package it is now easier to declare providers You no longer need to write your providers by hand or wonder which particular provider will suit your use case All you need to do is follow the syntax for defining your Riverpod code generator and annotate your code then with build runner you can generate all your providers For instance this is the code generation syntax for these different Riverpod providersFor Providers riverpodint foo FooRef ref gt For FutureProviders riverpodFuture lt int gt foo FooRef ref async return For StateProviders riverpodclass Foo extends Foo override int build gt You can notice that there is a pattern for creating the providers Once you put the correct syntax you can generate the providers just like that Notifier ProviderRiverpod came with the addition of two new provider types the NotifierProvider and the AsyncNotifierProvider Riverpod recommends you use the NotifierProvider instead of the ChangeNotifier and StateNotifier providers so we are focusing on these two The NotifierProvider is used to listen to and expose a Notifier A Notifier exposes a state that can change over time Let s consider a simple example We will build a random string generator with two buttons one to generate a new string and the other to clear the entire list of strings In this example we will also be using the Riverpod code generator First using Riverpod annotation and the code syntax below we will create a NotifierProvider We will also add the functions for adding a random string and clearing the list of strings We will add the name of the file to be generated by specifying with part as seen in the code Note The name of the file to be generated is the same as the name of the current file you are working on When specifying it with part you will need to add g dart as that is how Riverpod generated files are named import package riverpod annotation riverpod annotation dart part notifier list provider g dart riverpodclass RandomStrNotifier extends RandomStrNotifier override List lt String gt build return using Dart s spread operator we create a new copy of the list void addString String randomStr state state randomStr void removeStrings state From our code we can see that the RandomStrNotifier returns an empty List then we added the two functions to add to the list and clear the list NotifierProvider and AsyncNotifierProvider support immutable state because our state is immutable we can not say state add or state remove So we create a new copy of the list state is used for updating the UI state To run the code generator run this command on the terminal flutter pub run build runner watch delete conflicting outputsAfter it has successfully run you can see your generated provider file in your project tab in your code editor From the image above you can see how the generated file will look like Note If you get the error Could not find a file named pubspec yaml in C Users … then run the dart pub get command on your terminal Moving on let s add this provider and the functions to our UIWidget build BuildContext context ref rebuid the widget when there is a change List lt String gt randomStrList ref watch randomStrNotifierProvider final random Random return Scaffold appBar AppBar title const Text RiverPod Notifier Example App backgroundColor Colors brown body SingleChildScrollView child Column children Column children map to a list randomStrList map string gt Container alignment Alignment center margin const EdgeInsets only bottom top height width color Colors brown child Text string toString style const TextStyle color Colors white Row mainAxisAlignment MainAxisAlignment spaceAround children ElevatedButton icon icon const Icon Icons add label const Text Generate style ElevatedButton styleFrom backgroundColor Colors brown Background color onPressed add string to list function ref read randomStrNotifierProvider notifier addString This is the random String random nextInt ElevatedButton icon icon const Icon Icons clear label const Text Clear style ElevatedButton styleFrom backgroundColor Colors brown Background color onPressed clear list function ref read randomStrNotifierProvider notifier removeString As you can see the Riverpod code generator generated a matching randomStrNotifierProviderWhen you run the app it should look like this AsyncNotifierProviderThe AsyncNotifierProvider is used to listen to and expose an asyncNotifier The AsyncNotifier is a notifier that is asynchronously initialized Let s dive into the exampleWe will be building a simple app that loads a list of products after a time duration of seconds with a button to clear the list of products First we will use the Freezed code generator tool to create our product class Then using the copyWith method we will create the product objects that will be going into our list We will add the name of the file to be generated by specifying with part as seen in the code The name of the generated file is the current name of your file and freezed dart This is how the freezed files are named import package freezed annotation freezed annotation dart replace with part name of your file freezed dart part async notifier list provider freezed dart freezedclass Product with Product const Product const factory Product String name String description Product const Product product Product name Dart course for beginners description This is course will make you a dart star final Product product product copyWith description This course will make you a pro final Product product product copyWith name Ultimate Dart course for beginners final products product product product We can run this command on the terminal to generate the freezed fileflutter pub run build runner watch delete conflicting outputsThe image above shows how the Freezed generated file will look like We used the copyWith method to create new objects of product that we added to the list The copyWith method is used for returning a new object with the same properties as the original but with the values you have specified it is used when working with immutable structures like Freezed Now we will go ahead and add our Riverpod provider class which will be fetching the list of products after seconds We will also add the function to clear the list of products as well replace with part name of your file g dart part async notifier list provider g dart riverpodclass AsyncProducts extends AsyncProducts Future lt List lt Product gt gt fetchProducts async await Future delayed const Duration seconds return products override FutureOr lt List lt Product gt gt build async return fetchProducts Future lt void gt clearProducts async state const AsyncValue loading state await AsyncValue guard async await Future delayed const Duration seconds return The asyncNotifierProvider returns a future list of products To modify the UI we will now create the clearProducts function using AsyncValue class we can easily manage the loading error state and data state Looking at the AsyncValue class AsyncValue guard is used to transform a Future that can fail into something safe to read it is recommended to use this instead of try and catch blocks it will handle both the data and error states Next run this command on the terminal to generate the necessary Freezed and Riverpod codeflutter pub run build runner watch delete conflicting outputsLet s add this provider and function to our UIWidget build BuildContext context WidgetRef ref final productProvider ref watch asyncProductsProvider return Scaffold appBar AppBar title const Text AsyncNotifier actions IconButton icon const Icon Icons clear color Colors white onPressed ref read asyncProductsProvider notifier clearProducts body Container child productProvider when data products gt ListView builder itemCount products length itemBuilder context index return Padding padding const EdgeInsets only left right top child Card color Colors blueAccent elevation child ListTile title Text products index name style const TextStyle color Colors white fontSize subtitle Text products index description style const TextStyle color Colors white fontSize error err stack gt Text Error err style const TextStyle color Colors white fontSize loading gt const Center child CircularProgressIndicator color Colors blue Here we can see that by calling ref watch we can access our provider then we add the clear product function to the onPressed by calling ref read Now we can handle the different states of the response using productProvider whenWhen you run the app it should look like this RecapWe have come to the end of this tutorial Here we have learned that The NotifierProvider listens to and exposes a notifier when there is a change in state it automatically updates the UI AsyncNotifierProvider is used to listen and expose a notifier that is asynchronously initialized Using code generation tools like Freezed and Riverpod code generators we can easily generate data and provider classes with very little code The copyWith method used to create a new object but with values you specified when working with immutable classes Finally the AsyncValue class is used to efficiently handle data loading and error states ConclusionCongratulations you have successfully learned how to use Riverpod s newest providers NotifierProvider and AsyncNotifierProvider to manage state how to use code generation tools to generate code and how to use copyWith method and AsyncValue class If you enjoyed this article do well to leave a reaction and follow me for more content If you have any questions or spot any errors please do leave feedback ReferencesRiverpod Docs 2023-03-25 11:05:00
ニュース BBC News - Home Tornadoes kill 23 and bring devastation to Mississippi https://www.bbc.co.uk/news/world-us-canada-65075276?at_medium=RSS&at_campaign=KARANGA areas 2023-03-25 11:25:02
ニュース BBC News - Home Massive asteroid to pass by Earth on weekend https://www.bbc.co.uk/news/science-environment-65061818?at_medium=RSS&at_campaign=KARANGA large 2023-03-25 11:57:18
ニュース BBC News - Home UK asylum plans: Plans on future of migrant hotels to be announced https://www.bbc.co.uk/news/uk-65074419?at_medium=RSS&at_campaign=KARANGA announcedthe 2023-03-25 11:45:21

コメント

このブログの人気の投稿

投稿時間: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件)