AngularJS Services

Book Description

Design, build, and test services to create a foundation for your AngularJS applications

In Detail

This book provides you with the skills and best practices needed to create AngularJS services. It starts with the fundamentals of what services are and their role in a typical AngularJS application. You will walk through the development of a real-world application using services across the various application layers and then move on to create services that provide cross-cutting concerns such as messaging, logging, and authentication.

Next, the book covers services that provide data access showing you how to interact with external cloud-based data services and how to cache data on the client to reduce network latency. The book then shows you how to write services that leverage other cloud-based services to create mashups and include functionality in your application without writing a lot of code.

You will also learn how to create business logic objects, rules engines, and finite state machines, which can be used to provide business logic for your application.

What You Will Learn

  • Write Jasmine scenarios to test your AngularJS services
  • Implement common functionality that can be leveraged by the controllers, directives, and other services in your application
  • Build services that create, retrieve, update, and delete your application's data on external servers
  • Incorporate third-party JavaScript libraries into your AngularJS application
  • Move business logic to the client side to build a new class of serverless applications
  • Optimize your AngularJS application for maximum performance

Publisher Resources

Download Example Code

Table of Contents

  1. AngularJS Services
    1. Table of Contents
    2. AngularJS Services
    3. Credits
    4. About the Author
    5. About the Reviewers
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. The Need for Services
      1. AngularJS best practices
      2. Responsibilities of controllers
      3. Responsibilities of directives
      4. Responsibilities of services
      5. Summary
    9. 2. Designing Services
      1. Measure twice, and cut once
      2. Defining your service's interface
        1. Focus on the developer, not yourself
        2. Favor readability over brevity
        3. Limit services to a single area of responsibility
        4. Keep method naming consistent
        5. Keep to the top usage scenarios
        6. Do one thing only
        7. Document your interface
      3. Designing for testability
        1. Law of Demeter
        2. Pass in required dependencies
        3. Limiting constructors to assignments
        4. Use promises sparingly
      4. Services, factories, and providers
      5. Structuring your service in code
      6. Configuring your service
      7. Summary
    10. 3. Testing Services
      1. The basics of a test scenario
      2. Loading your modules in a scenario
      3. Mocking data
      4. Mocking services
      5. Mocking services with Jasmine spies
      6. Handling dependencies that return promises
      7. Mocking backend communications
      8. Mocking timers
      9. Summary
    11. 4. Handling Cross-cutting Concerns
      1. Communicating with your service's consumers using patterns
      2. Managing user notifications
      3. Logging application analytics and errors
      4. Authentication using OAuth 2.0
      5. Summary
    12. 5. Data Management
      1. Models provide the state and business logic
      2. Implementing a CRUD data service
      3. Caching data to reduce network traffic
      4. Transforming data in the service
      5. Summary
    13. 6. Mashing in External Services
      1. Storing events with Google Calendar
      2. Using Google Tasks to build a brewing task list
      3. Tying the Google Calendar and task list together
      4. Summary
    14. 7. Implementing the Business Logic
      1. Encapsulating business logic in models
      2. Encapsulating business logic in services
      3. Models or services, which one to use?
      4. Controlling a view flow with a state machine
      5. Validating complex data with a rules engine
      6. Summary
    15. 8. Putting It All Together
      1. Wiring in authentication
      2. Displaying notifications and errors
      3. Controlling the application flow
      4. Displaying data from external services
      5. Building and calculating the recipe
      6. Messaging is the heart of the application
      7. Summary
    16. Index

Product Information

  • Title: AngularJS Services
  • Author(s):
  • Release date: August 2014
  • Publisher(s): Packt Publishing
  • ISBN: 9781783983568