00 kun 00 soat 00 daqiqa 00 sekund

Sizning oxirgi imkoniyatingiz! 'Lituz' promokodi bilan 30% chegirmadan foydalaning!

Pro Kotlin Web Apps from Scratch: Building Production-Ready Web Apps Without a Framework – August Lilleaas

34990 UZS

-Do'stlaringizga tafsiya etish!

Tasnif

«Pro Kotlin Web Apps from Scratch: Building Production-Ready Web Apps Without a Framework» authored by August Lilleaas is an indispensable resource for developers seeking to harness the full potential of Kotlin in web application development, without relying on conventional frameworks.

In this comprehensive guide, Lilleaas takes readers on a journey through the process of building robust and scalable web applications entirely from scratch, leveraging the power and flexibility of Kotlin. By eschewing traditional frameworks, developers gain a deeper understanding of the underlying mechanisms of web development while maximizing the performance and efficiency of their applications.

The book covers a wide array of topics essential for building production-ready web apps, including routing, templating, database interaction, authentication, security, and deployment strategies. Lilleaas provides clear explanations, practical examples, and best practices, ensuring that readers are equipped with the knowledge and skills needed to tackle real-world development challenges.

Throughout the book, Lilleaas emphasizes the importance of writing clean, maintainable code and adopts a pragmatic approach to development, prioritizing simplicity and efficiency without sacrificing functionality or performance. By the end of the book, readers will have a comprehensive understanding of Kotlin’s capabilities in web development and the confidence to build sophisticated, production-ready web applications from scratch.

Whether you’re a seasoned developer looking to expand your toolkit or a newcomer eager to explore the world of web development with Kotlin, «Pro Kotlin Web Apps from Scratch» is an invaluable resource that empowers developers to unleash the full potential of Kotlin in building modern, high-performance web applications.

Qo'shimcha ma'lumot

Varaqlar soni:

327

Mundarija

About the Author …….xv
About the Technical Reviewer …..xvii
Acknowledgments…….xix
Introduction…….xxi
Part I: Up and Running with a Web App….1
Chapter 1: Setting Up a Development Environment…. 3
Get Started with IntelliJ IDEA Community Edition….. 3
Download and Run IntelliJ IDEA …… 4
Create a New Kotlin Project with IntelliJ IDEA….. 4
Kotlin Hello, World!…….. 9
Kotlin Naming Conventions ……. 9
Write Some Code…….. 9
Run Your Code with IntelliJ IDEA …… 11
Run Your Code with Gradle ……. 12
IntelliJ IDEA Tips and Tricks ……. 13
Look Out for the Progress Bar …… 14
Remember to Refresh the Gradle Project in IntelliJ IDEA…. 15
Embrace Auto-completion in IntelliJ IDEA….. 16
Chapter 2: Setting Up the Web App Skeleton…. 19
Web Server Hello, World!……. 20
Choosing Ktor…….. 20
Add the Ktor Library ……. 20
Start a Web Server…….. 21
Extracting to a Separate Function …… 22
Using Lambdas…….. 23
Named Arguments Instead of Magic Numbers and Booleans … 24
Run Your Web App…….. 25
Logging ……… 26
Loggers on the Java Platform…… 26
Configure Logging in Your Web App…… 27
Write to the Log from Your Own Code…… 30
A Note on “Magic” XML Config Files …… 32
Useful Error Pages …….. 33
Chapter 3: Configuration Files ….. 37
Create a Configuration File ……. 38
The Configuration File Anatomy…… 38
Reading Values from Your Configuration File….. 39
Make the Configuration Fail Early and Type-Safe ….. 40
Store Configuration in a Data Class…… 41
Load Config into the Data Class…… 42
Kotlin Null Safety …….. 42
Kotlin Platform Types……. 43
Use the Data Class in Your Web App…… 44
Use let Blocks to Avoid Intermediate Variables ….. 45
Provide Different Default Values for Different Environments …. 46
Environment-Specific Config Files …… 46
Define the Web App Environment …… 47
Override Defaults with Environment-Specific Config …. 47
Secret Config Values …….. 48
Don’t Store Secrets in Version Control …… 48
Logging Config on Web App Startup…… 51
Format the Output …….. 52
Masking Secrets…….. 52
Writing to the Log …….. 53
Chapter 4: Decoupling Web Handlers from Specific Libraries.. 55
Your Own HTTP Response Abstraction…… 56
Representing HTTP Responses…… 56
Multiple Response Types ……. 57
Convenience Functions for Headers…… 59
Case-Insensitive Headers……. 64
The fold Function…….. 65
Destructuring Assignment……. 66
Connecting to Ktor …….. 67
Ktor Route Mapping……. 67
Extension Functions ……. 68
Functions Returning Functions…… 69
Map Headers …….. 70
Map TextWebResponse and Status Code….. 71
Map JsonWebResponse ……. 72
Using the New Mapping ……. 74
A Note on Overengineering ……. 75
Part II: Libraries and Solutions…..77
Chapter 5: Connecting to and Migrating SQL Databases … 79
Connecting to a SQL Database……. 80
The Connection Pool……. 80
Installing the Database Driver …… 81
Setting Up H2…….. 82
Updating WebappConfig ……. 82
Set Up the Connection Pool ……. 84
Creating a Connection ……. 85
The Initial Schema …….. 86
Installing Flyway…….. 86
Running Flyway During Startup…… 86
Creating the Initial Schema ……. 88
Managing Schema Changes ……. 89
Don’t Edit Migrations After Run …… 89
Adding More Schema ……. 90
Adding Non-nullable Columns …… 90
Backward-Compatible Migrations …… 92
Insert Seed Data …….. 93
Repeatable Migrations……. 93
Updating Repeatable Migrations …… 94
Handling Failed Migrations ……. 95
Failed Migrations Locally……. 95
Failed Migrations in Production…… 95
Rerunning Failed Migration ……. 96
Manually Performing Migration…… 96
Chapter 6: Querying a SQL Database….. 97
Setting Up Querying…….. 97
Use SQL Directly …….. 98
Installing Kotliquery……. 99
Mapping Query Results ……. 99
Execute SQL Queries…….. 100
Creating a Session……. 100
Querying for Single Rows……. 101
Querying for Multiple Rows ……. 101
Inserting Rows…….. 103
Updating and Deleting ……. 104
Positional vs. Named Parameters…… 104
Additional Operations ……. 105
Querying from Web Handlers ……. 105
Creating a Helper Function……. 105
A Note on Architecture……. 107
Avoid Long-Running Connections…… 107
Maps vs. Data Classes ……. 108
Passing Around Maps……. 108
Passing Individual Properties …… 109
Mapping to a Data Class……. 110
Database Transactions……. 113
Creating Transactions ……. 113
Transactions in Web Handlers …… 114
Type-Safe Transactional Business Logic ….. 115
Nested Transactions ……. 116
Chapter 7: Automated Tests with jUnit 5 …. 119
Setting Up Your Environment ……. 119
Adding jUnit 5 and kotlin.test …… 120
Writing a Failing Test ……. 121
Running a Failing Test ……. 121
Making the Test Pass……. 123
Writing Web App Tests……. 125
Setting Up the Basics ……. 125
Writing a Failing Test ……. 126
Making the Test Pass……. 128
Avoiding Leaky Tests…….. 129
Leaky Tests…….. 129
Avoiding Leaks with Transactions …… 130
Avoiding Leaks with Relative Asserts…… 133
Test-Driven Development……. 135
Design and Verification……. 135
Writing a Failing Test ……. 135
Making the Test Pass……. 137
Notes on Methodology ……. 137
What About Front-End Tests? …… 137
Real Database Writes vs. Mocks …… 138
Unit vs. Integration Tests ……. 139
Chapter 8: Parallelizing Service Calls with Coroutines … 141
Preparing Your Web App……. 141
Implementing a Fake Service…… 142
Adding a Second Server……. 142
Understanding Coroutines……. 144
The delay Coroutine……. 144
The Problem with Threads……. 144
Suspending Instead of Locking …… 145
Coroutine Contexts ……. 145
Coroutines in Ktor……. 147
Parallelizing Service Calls……. 148
Adding Dependencies……. 148
Performing Parallelized Calls …… 149
Handling Race Conditions……. 151
Adding to Ktor…….. 151
Mixing Coroutines and Blocking Calls…… 152
Wrapping Blocking Calls……. 152
Coroutine Internals…….. 153
Kotlin vs. KotlinX…….. 153
Comparing with Arrow……. 154
Using Low-Level Continuations …… 157
Java Platform Implementation Details ….. 158
Chapter 9: Building Traditional Web Apps with HTML and CSS .. 161
Patterns and Organization……. 162
Generating HTML …….. 162
Using the kotlinx.html DSL ……. 162
Using the Ktor HTML DSL ……. 163
The Power of the DSL……. 164
Operator Overloading……. 165
Adding Custom Tags ……. 166
CSS and Assets …….. 167
Serving Static Files……. 167
Instant Reloading…….. 170
Reusable Layouts…….. 171
Adding a Layout…….. 172
Using the Layout…….. 173
Adding WebResponse for HTML…… 174
Implementing HtmlWebResponse …… 174
Extension Function Precedence …… 175
Responding with HtmlWebResponse…… 176
A Note on Abstractions ……. 178
User Security…….. 178
Password Hashing……. 178
Using Bcrypt for Hashing……. 179
Updating Your Migrations ……. 182
Adding a Login Form…….. 183
Wiring Up Your Web App ……. 183
Different Types of Sessions ……. 185
Adding a New Ktor Extension Function ….. 186
Configuring Session Cookies…… 187
Logging In…….. 189
Protecting Routes with Authentication ….. 191
Logging Out …….. 194
Chapter 10: Building API-Based Back Ends…. 197
Handling API Calls …….. 197
Parsing Input …….. 197
Validating and Extracting Input…… 198
Avoid Automatic Serialization…… 200
Internal vs. External APIs……. 202
Single-Page Apps…….. 202
Hosting Alongside API……. 202
Hosting Separately with CORS …… 204
Authenticating Users ……. 206
Native Apps …….. 207
Using Cookies for Authentication…… 207
Using JWTs for Authentication …… 207
Performing Authentication……. 211
Chapter 11: Deploying to Traditional Server Based Environments .. 213
Packaging as Self-Contained JAR Files …… 213
What’s a JAR File…….. 213
Self-Contained JAR Files ……. 214
Packaging with Gradle……. 215
Building the JAR File ……. 215
Executing the JAR File……. 216
Packaging for Production……. 217
Building Docker Images……. 217
Running Docker Images Locally …… 219
Deploying to Production ……. 220
Chapter 12: Building and Deploying to Serverless Environments .. 223
Detaching Your Code…….. 224
Separating Handlers from Ktor…… 224
Basic Structure…….. 225
Detached Web Handlers ……. 227
Run Web Handlers on AWS Lambda…… 227
Making AWS Lambda Web Handlers…… 227
Deploying to AWS Lambda……. 229
Calling Your Existing Handlers…… 237
Improving Performance ……. 243
Performance and Cold Starts …… 244
Initialization Time vs. Execution Time…… 244
Lazy Loading…….. 245
Initializing Correctly……. 246
Migrations and H2 ……. 248
Java Runtime Flags ……. 248
GraalVM, Kotlin/JS, and Kotlin Native …… 249
Chapter 13: Setup, Teardown, and Dependency Injection with Spring Context. 251
Why Spring and Dependency Injection? …… 252
Setting Up Spring Context……. 253
Adding Your Data Source ……. 254
lateinit in Kotlin…….. 256
Starting Your Web App……. 257
Extended Usage …….. 258
Chapter 14: Enterprise Authentication Using Spring Security.. 261
Preparing Your Web App……. 261
Setting Up Embedded Jetty ……. 261
Initializing the Servlet……. 264
Adding Ktor to Your Servlet……. 265
Using Spring Security ……. 267
Setting Up the Servlet Filter …… 267
Configuring Spring Security …… 269
Authenticating Users ……. 271
Filtering Requests……. 273
Accessing the Logged-In User…… 274
Part III: Tools of the Trade…..277
Chapter 15: Choosing the Right Library…. 279
What’s a Library? …….. 279
Popularity Is Largely Irrelevant ……. 280
Documentation and Stability Are Important….. 281
Avoid Following the “X Way”……. 281
Don’t Shy Away from Platform Libraries …… 282
Boundaries and Layers ……. 283
Chapter 16: An Assortment of Kotlin Tricks …. 285
Delegation (by lazy)…….. 285
Inline Functions…….. 286
Reified Generics…….. 288
Contracts……… 289
And So Much More…….. 290
Appendix A: Using Jooby Instead of Ktor …. 293
Appendix B: Using Hoplite Instead of Typesafe Config … 303
Appendix C: Using Spek Instead of jUnit 5…. 307
Index…….. 313

Fikr-mulohazalar

Baho berilmagan.

“Pro Kotlin Web Apps from Scratch: Building Production-Ready Web Apps Without a Framework – August Lilleaas&rdquo mahsulotiga birinchilardan bo'lib fikr bildiring;

Email manzilingiz chop etilmaydi. Majburiy bandlar * bilan belgilangan

O'xshash Kitoblar!

Bosh sahifa
E-kitoblar
0
Cart
Mening sahifam