0%

A developer's guide to designing, testing, and securing production-ready modern APIs with the help of practical ideas to improve your application's functionality

Key Features

  • Build resilient software for your enterprises and customers by understanding the complete API development life cycle
  • Overcome the challenges of traditional API design by adapting to a new and evolving culture of modern API development
  • Use Spring and Spring Boot to develop future-proof scalable APIs

Book Description

The philosophy of API development has evolved over the years to serve the modern needs of enterprise architecture, and developers need to know how to adapt to these modern API design principles. Apps are now developed with APIs that enable ease of integration for the cloud environment and distributed systems. With this Spring book, you'll discover various kinds of production-ready API implementation using REST APIs and explore async using the reactive paradigm, gRPC, and GraphQL.

You'll learn how to design evolving REST-based APIs supported by HATEOAS and ETAGs and develop reactive, async, non-blocking APIs. After that, you'll see how to secure REST APIs using Spring Security and find out how the APIs that you develop are consumed by the app's UI. The book then takes you through the process of testing, deploying, logging, and monitoring your APIs. You'll also explore API development using gRPC and GraphQL and design modern scalable architecture with microservices. The book helps you gain practical knowledge of modern API implementation using a sample e-commerce app.

By the end of this Spring book, you'll be able to develop, test, and deploy highly scalable, maintainable, and developer-friendly APIs to help your customers to transform their business.

What you will learn

  • Understand RESTful API development, its design paradigm, and its best practices
  • Become well versed in Spring's core components for implementing RESTful web services
  • Implement reactive APIs and explore async API development
  • Apply Spring Security for authentication using JWT and authorization of requests
  • Develop a React-based UI to consume APIs
  • Implement gRPC inter-service communication
  • Design GraphQL-based APIs by understanding workflows and tooling
  • Gain insights into how you can secure, test, monitor, and deploy your APIs

Who this book is for

This book is for inexperienced Java programmers, comp science, or coding boot camp graduates who have knowledge of basic programming constructs, data structures, and algorithms in Java but lack the practical web development skills necessary to start working as a developer. Professionals who've recently joined a startup or a company and are tasked with creating real-world web APIs and services will also find this book helpful. This book is also a good resource for Java developers who are looking for a career move into web development to get started with the basics of web service development.

Table of Contents

  1. Modern API Development with Spring and Spring Boot
  2. Contributors
  3. About the author
  4. About the reviewer
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  6. Section 1: RESTful Web Services
  7. Chapter 1: RESTful Web Service Fundamentals
    1. Technical requirements
    2. Introducing REST APIs
    3. REST history
    4. REST fundamentals
    5. Handling resources and URIs
    6. The URI syntax
    7. URLs
    8. URNs
    9. Exploring HTTP methods and status codes
    10. POST
    11. GET
    12. PUT
    13. DELETE
    14. PATCH
    15. HTTP status codes
    16. Learning HATEOAS
    17. Best practices for designing REST APIs
    18. 1. Use nouns and not verbs when naming a resource in the endpoint path
    19. 2. Use the plural form for naming the collection resource in the endpoint path
    20. 3. Use hypermedia (HATEOAS)
    21. 4. Always version your APIs
    22. 5. Nested resources
    23. 6. Secure APIs
    24. 7. Documentation
    25. 8. Status codes
    26. 9. Caching
    27. 10. Rate limit
    28. An overview of the e-commerce app
    29. Summary
    30. Questions
    31. Further reading
  8. Chapter 2: Spring Concepts and REST APIs
    1. Technical requirements
    2. Introduction to Spring
    3. The Inversion of Control pattern
    4. The Dependency Injection pattern
    5. The Aspect-Oriented Programming paradigm
    6. Learning the basic concepts of the Spring Framework
    7. IoC containers
    8. Defining beans
    9. Configuring beans using Java
    10. How to code DI
    11. Writing code for AOP
    12. Why use Spring Boot?
    13. Purpose of servlet dispatcher
    14. Summary
    15. Questions
    16. Further reading
  9. Chapter 3: API Specifications and Implementation
    1. Technical requirements
    2. Designing APIs with OAS
    3. Understanding the basic structure of OAS
    4. The metadata sections of OAS
    5. The servers and tags sections of OAS
    6. The components section of OAS
    7. The path section of OAS
    8. Converting OAS to Spring code
    9. Step 1 – adding the Gradle plugin
    10. Step 2 – defining the OpenAPI config for code generation
    11. Step 3 – defining the OpenAPI Generator ignore file
    12. Step 4 – defining a swaggerSources task in the Gradle build file
    13. Step 5 – adding swaggerSources to the compileJava task dependency
    14. Step 6 – adding the generated source code to Gradle sourceSets
    15. Step 7 – running the build for generating, compiling, and building the code
    16. Implementing the OAS code interfaces
    17. Adding a Global Exception Handler
    18. Testing
    19. Summary
    20. Questions
    21. Further reading
  10. Chapter 4: Writing Business Logic for APIs
    1. Technical requirements
    2. Overview of the service design
    3. Adding a Repository component
    4. @Repository annotation
    5. Database and JPA configuration
    6. The database and seed data script
    7. Adding entities
    8. Adding repositories
    9. Adding a Service component
    10. Implementing hypermedia
    11. Enhancing the controller with a service and HATEOAS
    12. Adding ETags to API responses
    13. Testing the APIs
    14. Summary
    15. Questions
    16. Further reading
  11. Chapter 5: Asynchronous API Design
    1. Technical requirements
    2. Understanding Reactive Streams
    3. Publisher
    4. Subscriber
    5. Subscription
    6. Processor
    7. Exploring Spring WebFlux
    8. Reactive APIs
    9. Reactive Core
    10. Understanding DispatcherHandler
    11. Controllers
    12. Functional endpoints
    13. Implementing Reactive APIs for our e-commerce app
    14. Changing OpenAPI Codegen for Reactive APIs
    15. Adding Reactive dependencies in build.xml
    16. Handling exceptions
    17. Adding hypermedia links to an API response
    18. Defining an entity
    19. Adding repositories
    20. Adding services
    21. Adding controller implementations
    22. Adding H2 Console to an application
    23. Adding application configuration
    24. Testing Reactive APIs
    25. Summary
    26. Questions
    27. Further reading
  12. Section 2: Security, UI, Testing, and Deployment
  13. Chapter 6: Security (Authorization and Authentication)
    1. Technical requirements
    2. Implementing authentication using Spring Security and JWT
    3. Learning how to authenticate using filters
    4. Adding the required Gradle dependencies
    5. Authentication using OAuth 2.0 Resource Server
    6. Exploring the fundamentals of JWT
    7. Securing REST APIs with JWT
    8. Learning new API definitions
    9. Modifying the API specification
    10. Storing the refresh token using a database table
    11. Implementing the JWT manager
    12. Implementing new APIs
    13. Implementing the REST controllers
    14. Configuring web-based security
    15. Configuring CORS and CSRF
    16. Understanding authorization
    17. Role and authority
    18. Testing security
    19. Summary
    20. Questions
    21. Further reading
  14. Chapter 7: Designing a User Interface
    1. Technical requirements
    2. Learning React fundamentals
    3. Creating a React app
    4. Exploring basic structures and files
    5. Understanding the package.json file
    6. Understanding how React works
    7. Exploring React components and other features
    8. Exploring JSX
    9. Exploring a component's state
    10. Styling components using Tailwind
    11. Configuration to remove unused styles in production
    12. Including Tailwind in React
    13. Designing e-commerce app components
    14. Consuming APIs using Fetch
    15. Writing the product API client
    16. Coding the Product Listing page
    17. Implementing authentication
    18. Creating a custom useToken hook
    19. Writing the Login component
    20. Writing the custom cart context
    21. Writing the Cart component
    22. Writing the Order component
    23. Writing the root (App) component
    24. Running the application
    25. Summary
    26. Questions
    27. Further reading
  15. Chapter 8: Testing APIs
    1. Technical requirements
    2. Testing APIs and code manually
    3. Testing automation
    4. Unit testing
    5. Code coverage
    6. Integration testing
    7. Summary
    8. Questions
    9. Further reading
  16. Chapter 9: Deployment of Web Services
    1. Technical requirements
    2. Exploring the fundamentals of containerization
    3. Building a Docker image
    4. Exploring Docker
    5. Configuring code to build an image
    6. Adding Actuator
    7. Configuring the Spring Boot plugin task
    8. Configuring the Docker registry
    9. Executing a Gradle task to build an image
    10. Deploying an application in Kubernetes
    11. Summary
    12. Questions
    13. Further reading
  17. Section 3: gRPC, Logging, and Monitoring
  18. Chapter 10: gRPC Fundamentals
    1. Technical requirements
    2. Introduction and gRPC architecture
    3. REST versus gRPC
    4. Can I call the gRPC server from web browsers and mobile apps?
    5. gRPC architecture overview
    6. Protocol Buffer
    7. Understanding service definitions
    8. Exploring the RPC life cycle
    9. The life cycle of unary RPC
    10. The life cycle of server-streaming RPC
    11. The life cycle of client-streaming RPC
    12. The life cycle of bidirectional streaming RPC
    13. Events that impact the life cycle
    14. Understanding the gRPC server and gRPC stub
    15. Handling errors
    16. Error status codes
    17. Summary
    18. Questions
    19. Further reading
  19. Chapter 11: gRPC-based API Development and Testing
    1. Technical requirements
    2. Writing an API interface
    3. Setting up the project
    4. Writing the payment gateway functionalities
    5. Developing the gRPC server
    6. Implementation of the gRPC base classes
    7. Implementation of the gRPC server
    8. Testing the gRPC server
    9. Handling errors
    10. Developing the gRPC client
    11. Implementing the gRPC client
    12. Testing the gRPC client
    13. Learning microservice concepts
    14. Design differences in monolithic and microservice-based systems
    15. Summary
    16. Questions
    17. Further reading
  20. Chapter 12: Logging and Tracing
    1. Technical requirements
    2. Introducing logging and tracing
    3. Understanding the ELK stack
    4. Installing the ELK stack
    5. Implementing logging and tracing
    6. Changing the gRPC server code
    7. Changing the gRPC client code
    8. Testing the logging and tracing changes
    9. Distributed tracing with Zipkin
    10. Executing Zipkin
    11. Summary
    12. Questions
    13. Further reading
  21. Section 4: GraphQL
  22. Chapter 13: GraphQL Fundamentals
    1. Technical requirements
    2. Introducing GraphQL
    3. Brief history of GraphQL
    4. Comparing GraphQL with REST
    5. Learning about the fundamentals of GraphQL
    6. Exploring the Query type
    7. Exploring the Mutation type
    8. Exploring the Subscription type
    9. Designing a GraphQL schema
    10. Understanding scalar types
    11. Understanding fragments
    12. Understanding interfaces
    13. Understanding Union types
    14. Understanding input types
    15. Tools that help with designing a schema
    16. Testing GraphQL queries and mutations
    17. Solving the N+1 problem
    18. Understanding the N+1 problem
    19. Solution for the N+1 problem
    20. Summary
    21. Questions
    22. Further reading
  23. Chapter 14: GraphQL API Development and Testing
    1. Technical requirements
    2. Workflow and tooling for GraphQL
    3. Implementation of the GraphQL server
    4. Creating the gRPC server project
    5. Adding the GraphQL DGS dependencies
    6. Adding the GraphQL schema
    7. Adding custom scalar types
    8. Implementing GraphQL queries
    9. Implementing GraphQL mutations
    10. Implementing GraphQL subscriptions
    11. Instrumenting the GraphQL API
    12. Documenting APIs
    13. Test automation
    14. Testing GraphQL queries
    15. Testing GraphQL mutations
    16. Testing GraphQL subscriptions
    17. Summary
    18. Questions
    19. Further reading
  24. Assessments
    1. Chapter 1 – RESTful Web Services Fundamentals
    2. Chapter 2 – Spring Concepts and REST APIs
    3. Chapter 3 – API Specifications and Implementation
    4. Chapter 4 – Writing Business Logic for APIs
    5. Chapter 5 – Asynchronous API Design
    6. Chapter 6 – Security (Authorization and Authentication)
    7. Chapter 7 – Designing the User Interface
    8. Chapter 8 – Testing APIs
    9. Chapter 9 – Deployment of Web Services
    10. Chapter 10 – gRPC Fundamentals
    11. Chapter 11 – gRPC-Based API Development and Testing
    12. Chapter 12 – Logging and Tracing
    13. Chapter 13 – GraphQL Fundamentals
    14. Chapter 14 – GraphQL API Development and Testing
    15. Why subscribe?
  25. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Leave a review - let other readers know what you think
18.117.196.217