Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Title Page
Copyright and Credits
Hands-On Swift 5 Microservices Development
Dedication
About Packt
Why subscribe?
Foreword
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
Introduction to Microservices
What is a microservice?
Rules for using microservices
Understanding why to choose microservices
Effective team management
Reusable code base
Flexible scope of functionality
Maintainability
Scalability
Auto-scaling
Flexible cost
Service-oriented availability
Mixed stacks
Understanding why not to choose microservices
Initially more work
Increased complexity
Debugging and troubleshooting
Who is using microservices?
Amazon
Netflix
Uber
A lot of other companies
Comparing monolith and microservices
Reusable code base
Multiple versions online
No downtime
Updates are as slow or fast as required
Common microservice use cases
Upgrading from monolith to microservices
Decoupling business logic
What does the application do?
What are the common components?
Reorganizing your monolith
Using authentication
Adjusting business logic
Integrating microservices
Summary
Questions
Understanding Server-Side Swift
Technical Requirements
A quick review of Swift
From Fortran to Swift
Swift performance
Scripting languages
Facebook
Twitter
Uber
VM languages
Native languages
Comparing frameworks
Swift's features
Swift on the server
Self-contained server
Linux/Ubuntu
Docker
SwiftNIO
Asynchronous events
Features of Swift 5
ABI stability
Raw strings and UTF8 strings
Result type
Future enum cases
Flattening nested optionals
Summary
Questions
Getting Started with the Vapor Framework
The Vapor framework
History of Vapor
Hello World
General structure
Configuration
Middleware
Services
RoutesBuilder
SwiftNIO – futures and promises
EventLoop
EventLoopFutures
map
flatMap
EventLoopPromises
Controllers
Content
Requests
Databases and models
Fluent and FluentKit
A Fluent model
Insert
Update
Delete
Querying
Supported databases
Views
Comparing Vapor to Kitura, Perfect, and Smoke
Vapor and Kitura
Vapor and Perfect
Vapor and Smoke
Installing Vapor
Prerequisites
Vapor in Action
Summary
Questions
Planning an Online Store Application
Technical requirements
Application layout for an online store
Frontend to API communication
Authentification
Generic authentication
Microservice authentication
JSON Web Tokens
Renewing JWTs
Access token
Refresh token
Block access
Database management
Cloud support
User Manager
Models
User
Address
Product Manager
Models
Products
Category
Product Categories
Order Manager
Models
Order
Order Product
Payment
API structure
Summary
Questions
Creating Your First Microservice
Technical requirements
Starting a new service
Version control
Using the API template
General file folders
Dependency management
Adding and removing packages
Configuration
Middleware
CORS
Error
Services
Router
DatabaseConfig
Fluent
Routes
Using models
I/O models
DB models
Returning DB models
Predefined models
Using controllers
Interacting with models
File management
SendGrid
Using workers
Summary
Questions
Application Structure and Database Design
Technical requirements
Understanding project setup and folder structure
Installing Git and Docker
Installing Git
Installing Docker
Using Docker with microservices
Setting up Docker and Git with AWS and GitHub
Setting up Vapor and the database
Setting up our services
Setting up Dockerfiles
Setting environment variables
Running the entire application
Summary
Questions
Writing the User Service
Technical requirements
Setting up and taking the first step
Setting up the template
Installing SendGrid
Setting up a JWT and utility functions
Setting up the database
Exploring routes
Exploring models
Database models
User
Address
Connecting models to Fluent
I/O models
Access token
Refresh token
Response models
Input models
Connecting response models to the database model
Logging in and registering
Preparations
Registration
Login
Refresh access token
Managing users
Preparations
Profile
Update
Delete
Understanding address management
Preparing the controller and routes
Getting addresses
Creating addresses
Updating addresses
Deleting addresses
Starting the service
Summary
Questions
Testing Microservices
Technical requirements
Understanding unit tests
Defining unit tests
Defining functional tests
Setting up Xcode
Unit tests for microservices
Functional tests versus unit tests
Unit test pros and cons
Functional test pros and cons
Trying functional tests via Postman
Installing Postman
Setting up Postman
Testing with Postman
Using isolation as a feature
Reusable services
Controlled testing
Testing multiple services together
Configuration
What to test?
Testing locally
Summary
Questions
Product Management Service
Technical requirements
Setting up the project
Setting up the template
Setting up JWT verification
Setting up the database
Developing routes
Writing the models we need
Creating database models
Creating I/O models
The payload model
Writing the controllers we need
Writing CategoriesController
Writing ProductsController
Testing the service
Summary
Questions
Understanding Microservices Communication
Technical requirements
Understanding when to communicate
Understanding data verification
Understanding data processing
Understanding data aggregation
Understanding data management
Exploring good communication
Asynchronous communication
What to avoid
Understanding Message and Event Systems
Message Systems
Event Systems
REST and WebSocket APIs
Advantages of WebSockets
Defining the interface
Advantages of REST
Leveraging Swift
Shared libraries
Generic functions and classes
Summary
Questions
Order Management Service
Technical requirements
Getting started
Setting up the template
Setting up JWT verification
Setting up the database
Configuring Vapor
Creating our routes
Creating our models
Configuring database models
Writing input models
Writing output models
Creating our controllers
Writing the OrderController
Writing the ProcessingController
Extending the order management service
Adding taxes
Adding payment methods
Adding refunds and coupons
Summary
Questions
Best Practices
Technical requirements
Simplicity for maintainability and stability
Simplicity through libraries
Using straightforward names
Separation of concerns
Embracing Swift language perks
Using extensions
Exploring protocols
Using generic functions
Using abstract and concrete implementations
Combining microservices
Troubleshooting and debugging microservices
Using Xcode for debugging
Using lldb for debugging
Stage and live systems
Summary
Questions
Hosting Microservices
Technical requirements
Setting up a microservice environment
Starting with a simple service
Managing databases and microservices
Using the power of a load balancer
Final setup
Exploring Swift on Linux
The current state of Swift on Linux
Installing Linux on Ubuntu
Running Swift via Docker
Environment variables
Summary
Questions
Docker and the Cloud
Technical requirements
Exploring Docker Containers and Images
Setting up Docker
Images, Repositories, and Containers
Repositories
Images
Containers
Starting Hello World
Running Docker with AWS
Running Docker in Google Cloud
Running Docker with Digital Ocean
Using Kubernetes
Summary
Questions
Deploying Microservices in the Cloud
Technical requirements
Setting up AWS and a Docker repository
Setting up ECS
Using CodePipeline for CD
Summary
Questions
Scaling and Monitoring Microservices
Technical requirements
Scaling microservices and the importance of monitoring
Monitoring
Scaling
Scaling and monitoring using AWS
Scaling and monitoring using Google Cloud
Scaling and monitoring using DigitalOcean
Additional cloud providers
Heroku
IBM Cloud
Microsoft Azure
Oracle Cloud
Summary
Questions
Assessment Answers
Chapter 1: Introduction to Microservices
Chapter 2: Understanding Server-Side Swift
Chapter 3: Getting Started with the Vapor Framework
Chapter 4: Planning an Online Store Application
Chapter 5: Creating Your First Microservice
Chapter 6: Application Structure and Database Design
Chapter 7: Writing the User Service
Chapter 8: Testing Microservices
Chapter 9: Product Management Service
Chapter 10: Understanding Microservices Communication
Chapter 11: Order Management Service
Chapter 12: Best Practices
Chapter 13: Hosting Microservices
Chapter 14: Docker and the Cloud
Chapter 15: Deploying Microservices in the Cloud
Chapter 16: Scaling and Monitoring Microservices
Other Books You May Enjoy
Leave a review - let other readers know what you think
← Prev
Back
Next →
← Prev
Back
Next →