Giter Club home page Giter Club logo

beersample-java2's Introduction

beersample-java2

A sample application for the Java SDK 2.0 and Couchbase Server 3.0

Note: this is a rewrite of the previous SDK 2.0 tutorial material, for 2.1+ releases. You can find the previous material on the oldtutorial branch, see it here on github.

What's needed?

  • The beersample sample bucket
  • The beer/brewery_beers view (built in in beersample sample)
  • An additional view beer/by_name with the following map function (you should copy the beer designdoc to dev in order to edit it and add this view):
    function (doc, meta) {
       if (doc.type == "beer") {
         emit(doc.name, doc.brewery_id)
       }
     }

Building and running

Correctly configure the application for your couchbase installation by editing src/main/resources/application.yml.

To build a self-contained jar of the application, run the following Maven command:

mvn clean package

To run the application and expose the REST API on localhost:8080, run the following command:

java -jar target/beersample2-1.0-SNAPSHOT.jar

REST API

The REST API is deployed on port 8080 and has the following routes:

Beer Routes

  • GET /beer/{id}: retrieve the Beer with id {id} (one json object representing the beer)
  • POST /beer: with a jsonObject in body representing the beer data, creates a new beer
  • PUT /beer/{id}: with a jsonObject in body representing the updated beer data, updates a beer of id {id}
  • DELETE /beer/{id}: deletes the beer of id {id}
  • GET /beer: list all the beers, just outputting the beers id and name in an array of JSON objects
  • GET /beer/search/{partOfName}: list all the beers which name's contains {partOfName} (ignoring case). Each returned beer is represented as a JSON object with the beer's id and name and the whoe beer details under detail.
{
    "id": "theBeerId",
    "name": "The Beer",
    "detail": {
        "name": "The Beer",
        "category": "German Ale",
        ...
    }
}

Brewery Routes

  • GET /brewery/{id}: retrieve the details of brewery {id}, along with the list of beers produced by this brewery (in a sub-array beers, one JSON object for each beer having the beer's id under id and the beer's detail under beer).
"beers": [
    {
        "id": "theBeerId",
        "beer": {
            "name": "someBeer",
            "category": "German Ale",
            ...
        }
    },
    ...
]

beersample-java2's People

Contributors

paintscratcher avatar simonbasle avatar

Watchers

 avatar

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.