GithubHelp home page GithubHelp logo

raouf25 / spring-boot-efficient-search-api Goto Github PK

View Code? Open in Web Editor NEW
81.0 3.0 28.0 231 KB

Home Page: https://medium.com/quick-code/spring-boot-how-to-design-efficient-search-rest-api-c3a678b693a0?source=friends_link&sk=a9344c624d6e61b0fa8f42a9e1fcfcbe

License: Apache License 2.0

Java 93.48% Dockerfile 6.52%
rest-api java search spring-boot specification api design

spring-boot-efficient-search-api's Introduction

Spring Boot: How to design an efficient REST API?

Quality Gate Status

Resource collections are often enormous, and when some data has to be retrieved from them, it would be only not very efficient to always get the full list and browse it for specific items. Therefore we should design an optimized Search API.

  • Filtering:

    • Narrow down query results by parameters (e.g., country, creation date).
      GET /api/cars?country=Japan
      GET /api/cars?createDate=2019-11-11
  • Sorting:

    • Sort results ascending or descending by chosen parameters (e.g., by date).
      GET /api/cars?sort=createDate,asc
      GET /api/cars?sort=createDate,desc
  • Paging:

    • Use "limit" to restrict results and "offset" to specify which part of the result range to show.
      GET /api/cars?limit=100
      GET /api/cars?offset=2

Combine features:

GET /api/cars?country=Japan&sort=createDate,desc&limit=100&offset=2

Results in the list of 100 cars from Japan, sorted by creation date in descending order, starting from the second page (records 101-200).

How to Run the Project

Clone source code from git
$ git clone https://github.com/Raouf25/Spring-Boot-efficient-search-API.git
Build Docker image
$ docker build -t="spring-boot-efficient-search-api" --force-rm=true .

This command runs Maven build to create a JAR package and builds the Docker image.

Note: Initial command may take time to download the base image from DockerHub

Run Docker Container
$ docker run -p 8080:8080 -it --rm spring-boot-efficient-search-api
Test Application
$ curl localhost:8080/api/cars/1

Response:

{
   "id":1,
   "manufacturer":"Acura",
   "model":"Integra",
   "type":"Small",
   "country":"Japan",
   "createDate":"1931-02-01"
}
Stop Docker Container
docker stop $(docker container ls | grep "spring-boot-efficient-search-api:*" | awk '{ print $1 }')

Live Demo

This project is deployed on https://spring-boot-efficient-search-api.fly.dev/api/cars

Try: Demo Link

Docker Image Repository

Docker Image: raouf25/spring-boot-efficient-search-api

Refer to the Docker Commands section for pulling, running, and querying the API using cURL and jq.

License

For more details please see this medium post .

Spring Boot Efficient Search Api Copyright © 2020 by Abderraouf Makhlouf [email protected]

spring-boot-efficient-search-api's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar raouf25 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spring-boot-efficient-search-api's Issues

limit and offset not working

Just was testing your API and noticed that the limit and offset parms are not working, however using the page headers work fine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.