Code Monkey home page Code Monkey logo

contentstack-java's Introduction

Contentstack

Java SDK for Contentstack

Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. Read More.

Contentstack provides Java SDK to build application on top of Java. Given below is the detailed guide and helpful resources to get started with our Java SDK.

Prerequisite

You will need JDK installed on your machine. You can install it from here.

Setup and Installation

To use the Contentstack Java SDK to your existing project, perform the steps given below:

Group id: com.contentstack.sdk

Artifact id: java

{ version }

  1. Maven
<dependency>
  <groupId>com.contentstack.sdk</groupId>
  <artifactId>java</artifactId>
  <version>{version}</version>
</dependency>
  1. Gradle
implementation 'com.contentstack.sdk:java:{version}'

Get updated version from version

Key Concepts for using Contentstack

Stack

A stack is like a container that holds the content of your app. Learn more about Stacks.

Content Type

Content type lets you define the structure or blueprint of a page or a section of your digital property. It is a form-like page that gives Content Managers an interface to input and upload content. Read more.

Entry

An entry is the actual piece of content created using one of the defined content types. Learn more about Entries.

Asset

Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded to Contentstack. These files can be used in multiple entries. Read more about Assets.

Environment

A publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published. Learn how to work with Environments.

Contentstack Java SDK: 5-minute Quickstart

Initializing your SDK

To initialize the SDK, specify application API key, access token, and environment name of the stack as shown in the snippet given below:

Stack stack=Contentstack.stack("apiKey","accessToken","environment");

To get the API credentials mentioned above, log in to your Contentstack account and then in your top panel navigation, go to Settings > Stack to view the API Key and Access Token.

Querying content from your stack

To retrieve a single entry from a content type use the code snippet given below:

//stack is an instance of Stack class
ContentType contentType = stack.contentType("content_type_uid");
Entry entry = contentType.entry("entry_uid");
entry.fetch(new EntryResultCallBack(){
@Override
public void onCompletion(ResponseType responseType, Error error){
    if(error==null){
        //Success block
    }else{
        //Error block
    }}
});
Get Multiple Entries

To retrieve multiple entries of a particular content type, use the code snippet given below:

//stack is an instance of Stack class
Query query = stack.contentType("content_type_uid").query();
query.find(new QueryResultsCallBack(){
@Override
    public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
        if(error == null){
           //Success block
        }else{
           //Error block
    }}
});

Advanced Queries

You can query for content types, entries, assets and more using our Java API Reference.

Java API Reference Doc

Working with Images

We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.

For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/v3/assets/download?crop=300,400. There are several more parameters that you can use for your images.

Read Image Delivery API documentation.

You can use the Image Delivery API functions in this SDK as well. Here are a few examples of its usage in the SDK.

//set the image quality to 100
LinkedHashMap imageParams = new LinkedHashMap();
imageParams.put("quality", 100);
imageUrl = Stack.ImageTransform(imageUrl, imageParams);

//resize the image by specifying width and height
LinkedHashMap imageParams = new LinkedHashMap();
imageParams.put("width", 100);
imageParams.put("height",100);
imageUrl = Stack.ImageTransform(imageUrl, imageParams);

//enable auto optimization for the image
LinkedHashMap imageParams = new LinkedHashMap();
imageParams.put("auto", "webp");
imageUrl = Stack.ImageTransform(imageUrl, imageParams);

Helpful Links

contentstack-java's People

Contributors

dependabot[bot] avatar hiteshbal91 avatar ishaileshmishra avatar nandeesh-gajula avatar nikhilgohil11 avatar uttamukkoji 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.