Securing REST APIs with HTTP BASIC authentication

Security is no longer an afterthought, it's a must in any application these days.

Somnath Musib
Code Fountain
Published in
3 min readJan 3, 2021

--

Image Courtesy: https://unsplash.com/photos/-likB8H-IFk

In the modern era, security is an essential feature in any application, your REST services are no exception to it. In this short tutorial, we’ll discuss how to secure your REST APIs with BASIC authentication. We’ll use Spring Security to implement the security of the API

Application Endpoints

We’ll use a fictitious application that lets us manage our favorite web URLs. Let us call this application Pocket. It has the following endpoints:

GET /pockets: Returns all available pockets

GET /pockets/{id}: Returns the available pocket for the supplied id. Return an error for invalid ids

POST /pockets: Create a new pocket

PUT /pockets: Update an existing pocket

DELETE /pockets/{id}: Delete a pocket by the supplied id

Application Development

Let us now generate a Spring Boot project with the web, lombok, data-jpa, and H2 dependencies.

Let us now the Pocket model object:

--

--

Somnath Musib
Code Fountain

Educator | Software Developer, Cloud Architect | Author "Spring Boot In Practice" | Find more at https://musibs.github.io