Skip to content

Commit 46af46d

Browse files
🔒 Security update
Security update for all files
1 parent 99d39fc commit 46af46d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+9844
-0
lines changed

README.md

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/)
2+
3+
## Java SDK for Contentstack
4+
5+
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](https://www.contentstack.com/).
6+
7+
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.
8+
9+
10+
### Prerequisite
11+
12+
You will need JDK installed on your machine. You can install it from [here](http://www.oracle.com/technetwork/java/javase/downloads/jdk9-downloads-3848520.html).
13+
14+
### Setup and Installation
15+
16+
To use the Contentstack Java SDK to your existing project, perform the steps given below:
17+
18+
Group id: `com.contentstack.sdk`
19+
20+
Artifact id: `java`
21+
22+
[{ version }](https://search.maven.org/artifact/com.contentstack.sdk/java)
23+
24+
1. **Maven**
25+
```java
26+
<dependency>
27+
<groupId>com.contentstack.sdk</groupId>
28+
<artifactId>java</artifactId>
29+
<version>{version}</version>
30+
</dependency>
31+
```
32+
33+
2. **Gradle**
34+
```java
35+
implementation 'com.contentstack.sdk:java:{version}'
36+
```
37+
38+
_Get updated version from_ [_version_](https://search.maven.org/artifact/com.contentstack.sdk/java)
39+
40+
### Key Concepts for using Contentstack
41+
42+
#### Stack
43+
44+
A stack is like a container that holds the content of your app. Learn more about [Stacks](https://www.contentstack.com/docs/guide/stack).
45+
46+
#### Content Type
47+
48+
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](https://www.contentstack.com/docs/guide/content-types).
49+
50+
#### Entry
51+
52+
An entry is the actual piece of content created using one of the defined content types. Learn more about [Entries](https://www.contentstack.com/docs/guide/content-management#working-with-entries).
53+
54+
#### Asset
55+
56+
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](https://www.contentstack.com/docs/guide/content-management#working-with-assets).
57+
58+
#### Environment
59+
60+
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](https://www.contentstack.com/docs/guide/environments).
61+
62+
63+
64+
### Contentstack Java SDK: 5-minute Quickstart
65+
66+
#### Initializing your SDK
67+
68+
To initialize the SDK, specify application API key, access token, and environment name of the stack as shown in the snippet given below:
69+
```java
70+
Stack stack=Contentstack.stack("apiKey","accessToken","environment");
71+
```
72+
To get the API credentials mentioned above, log in to your Contentstack account and then in your top panel navigation, go to Settings &gt; Stack to view the API Key and Access Token.
73+
74+
75+
76+
#### Querying content from your stack
77+
78+
To retrieve a single entry from a content type use the code snippet given below:
79+
80+
```java
81+
//stack is an instance of Stack class
82+
ContentType contentType = stack.contentType("content_type_uid");
83+
Entry entry = contentType.entry("entry_uid");
84+
entry.fetch(new EntryResultCallBack(){
85+
@Override
86+
public void onCompletion(ResponseType responseType, Error error){
87+
if(error==null){
88+
//Success block
89+
}else{
90+
//Error block
91+
}}
92+
});
93+
```
94+
95+
##### Get Multiple Entries
96+
97+
To retrieve multiple entries of a particular content type, use the code snippet given below:
98+
99+
```java
100+
//stack is an instance of Stack class
101+
Query query = stack.contentType("content_type_uid").query();
102+
query.find(new QueryResultsCallBack(){
103+
@Override
104+
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
105+
if(error == null){
106+
//Success block
107+
}else{
108+
//Error block
109+
}}
110+
});
111+
```
112+
113+
114+
### Advanced Queries
115+
116+
You can query for content types, entries, assets and more using our Java API Reference.
117+
118+
[Java API Reference Doc](https://www.contentstack.com/docs/platforms/java/api-reference/)
119+
120+
### Working with Images
121+
122+
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.
123+
124+
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.
125+
126+
[Read Image Delivery API documentation](https://www.contentstack.com/docs/apis/image-delivery-api/).
127+
128+
You can use the Image Delivery API functions in this SDK as well. Here are a few examples of its usage in the SDK.
129+
130+
```java
131+
//set the image quality to 100
132+
LinkedHashMap imageParams = new LinkedHashMap();
133+
imageParams.put("quality", 100);
134+
imageUrl = Stack.ImageTransform(imageUrl, imageParams);
135+
136+
//resize the image by specifying width and height
137+
LinkedHashMap imageParams = new LinkedHashMap();
138+
imageParams.put("width", 100);
139+
imageParams.put("height",100);
140+
imageUrl = Stack.ImageTransform(imageUrl, imageParams);
141+
142+
//enable auto optimization for the image
143+
LinkedHashMap imageParams = new LinkedHashMap();
144+
imageParams.put("auto", "webp");
145+
imageUrl = Stack.ImageTransform(imageUrl, imageParams);
146+
```
147+
148+
### Helpful Links
149+
150+
- [Contentstack Website](https://www.contentstack.com)
151+
- [Official Documentation](https://contentstack.com/docs)
152+
- [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.contentstack.sdk;
2+
3+
import okhttp3.ResponseBody;
4+
import retrofit2.Call;
5+
import retrofit2.http.GET;
6+
import retrofit2.http.HeaderMap;
7+
import retrofit2.http.Url;
8+
9+
import java.util.LinkedHashMap;
10+
11+
public interface APIService {
12+
13+
@GET
14+
Call<ResponseBody> getRequest(@Url String url, @HeaderMap LinkedHashMap<String, Object> headers);
15+
}

0 commit comments

Comments
 (0)