Coder Social home page Coder Social logo

trendyol-data-eng-summer-intern-2019 / recom-engine-web-service Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 76 KB

Web-service component of the project, which is written with Spring Boot.

License: Apache License 2.0

Java 100.00%
spring-boot spring-kafka spring-mongodb java-8

recom-engine-web-service's Introduction

Recommendation Engine - Web Service Component

Description

This repository contains the web service (RESTful API) component of the recommender engine. The component is written using Spring Boot.

The API mainly uses two HTTP methods: POST and GET. POST method is for users to make reviews with score on a product. GET method is used for retrieving the user specific recommendations from MongoDB. If no entry for user is found in MongoDB, default list of recommendations is returned.

Usage

Run

This component cannot be run by itself. In order to run this component, all of the project components must be run using docker-compose. See Recommendation Engine - Docker Files

Making a POST Request

New review can be posted to the system by invoking POST request to the URL localhost:8080/users/{userId}/reviews. For example, if you want to post a review for user with id 2, you should send a POST request to following URL path:

localhost:8080/users/2/reviews

A request body of the following form must be specified for the POST request:

{
  "productId": "some_alphanumeric_id",
  "score": some_float_number,
  "timestamp": some_timestamp_greater_than_zero
}

Following header must be specified:

Content-Type: application/json

You can use the following command to post a new review to the system for user with id 2:

curl -H 'Content-Type: application/json' -d '{
  "productId": "3",
  "score": 4.5,
  "timestamp": 10
}' localhost:8080/users/2/reviews

Output:

{"productId":"3","score":4.5,"timestamp":"1970-01-01T00:00:00.010+0000","userId":"2"}

You can install jq and beautify the output as follows:

curl -H 'Content-Type: application/json' -d '{
  "productId": "3",
  "score": 4.5,
  "timestamp": 10
}' localhost:8080/users/2/reviews | jq

Output:

{
  "productId": "3",
  "score": 4.5,
  "timestamp": "1970-01-01T00:00:00.010+0000",
  "userId": "2"
}

Making a GET Request

User specific recommendations can be retrieved by invoking a GET request to the URL localhost:8080/users/{userId}/recommendations. User id of the user whom recommendations you want to retrieve is given in the URL path. For example, if you want to fetch the recommendations for the user with id 3, you should send a GET request to following URL path:

localhost:8080/users/3/recommendations

You can use the following command to retrieve recommendations for user with id 3:

curl local:8080/users/3/recommendations

Output:

{"_id":"3","recommendations":["100","101","102","103","104","105","106","107","108","109"]}

You can install jq and beautify the output as follows:

curl local:8080/users/3/recommendations | jq

Output:

{
  "_id": "3",
  "recommendations": [
    "100",
    "101",
    "102",
    "103",
    "104",
    "105",
    "106",
    "107",
    "108",
    "109"
  ]
}

Notes

If you want to change the component's source code and insert it into the project, you can follow these steps:

  • Clone docker repository: Recommender Engine - Docker Files.
  • Clone this repository, change the desired part of the source code.
  • Run sbt clean assembly in the root directory of this repository.
  • Move the created jar file target/scala-2.11/recom-engine-streaming-assembly-0.1.jar in this repo's root directory to images/spring-boot/target in docker repo's root directory.
  • Run docker-compose up in the docker repo's root directory.

Members

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.