Book Image

RESTful Web Services with Scala

By : Jos Dirksen
Book Image

RESTful Web Services with Scala

By: Jos Dirksen

Overview of this book

<p>RESTful web services are built to work best on the web. Scala provides a rich set of language constructs and advanced frameworks that you can use to create REST services. However, using Scala and these tools can be a complex task. There are many frameworks available and choosing the wrong framework or approach can cost a lot of time and lead to much frustration. By exploring the most popular Scala REST frameworks, you can make sure you choose the right tool.</p> <p>RESTful Web Services with Scala begins with a brief explanation of the REST architecture and its implementation in Scala, as well as the impact that REST architecture has on Scala applications. You will understand the advantages of building Scala web services and how existing Scala applications can take advantage of REST. This book will teach developers about the different programming paradigms available in the Scala world to create RESTful services by exploring the most popular Scala-oriented REST frameworks. It discusses the various facets of RESTful web services such as building scalable APIs, working with standards like HTTP and MIME, designing the architecture, securing the web service, and more.</p> <p>With this book, you will be able to build RESTful web services with various Scala frameworks such as Finch, Unfiltered, Scalatra, Akka-HTTP, and Play. You will create basic REST services using frameworks and then extend the REST services with custom functionality. By the end of the book, you'll be able to decide which framework is best suited for your requirements. We finish by looking at how we can use a number of advanced features provided by these frameworks, such as security, creating HTTP clients, working with HATEOAS, and more.</p>
Table of Contents (14 chapters)
RESTful Web Services with Scala
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

The REST service and model


To show the features of the various frameworks in this book and how they solve problems in a different manner, we'll define a simple API, which we'll implement with the REST frameworks. For this book, we'll implement a simple to-do list API.

API description

We want to create a RESTful API, so the most important part is to start with the description of the resources that can be managed through this API. For this API, we define the following resources:

Entity

Description

Task

A task is something that needs to be done. The JSON for a task looks similar to this:

{
  "id": long,
  "title": string,
  "content": string,
  "notes": [noteList],
  "status": Status,
     "assignedTo": Person,
}

Project

A project will allow us to group tasks together, and by assigning persons to a project, we can determine who can work on a specific task:

{
  "id": string,
  "title": string,
  "tasks": [task],
  "members": [person],
  "updated": datetime
}

Person

A person is someone who can work on a task and when done, close the task. A person can only work on those tasks to which he is assigned, or when he is part of the project to which a task belongs:

{
  "id": string,
  "name": string
}

Note

Notes can be added to tasks to provide additional information on how the task should be performed:

{
  "id": string,
  "text": string,
}

Without going into too much detail here, we want to support approximately the following functionality in our API:

  • CRUD functionality: We want to support some basic CRUD operations. It should be possible to perform the following actions:

    • Create, update, and delete a new task, project, person, and note.

    • Get a list of tasks, projects, persons, and notes.

    • Search through a list of tasks.

    • Add a note to a task. It should also be possible to update and delete the existing notes.

  • Advanced functions: Besides the standard CRUD-like functionality, we also want to provide some more advanced features:

    • Assign a task to a specific project

    • Assign a person to a task

    • Assign a person to a project

    • Move a task from one project to another

Note that we won't implement all the functionality for each framework. We'll mainly use this API to explain how we can use the various REST frameworks.