<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>st.com</groupId> <artifactId>springdemo</artifactId> <version>1.0-SNAPSHOT</version> <properties> <spring-framework.version>4.3.3.RELEASE</spring-framework.version> </properties> <dependencies> <!-- Spring Framework --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring-framework.version}</version> </dependency> <!-- Needed for RestTemplate --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring-framework.version}</version> </dependency> <!-- Used for Java to JSON and JSON to Java conversion --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.7.3</version> </dependency> </dependencies> <!-- Needed to use Java 8 --> <build> <finalName>springdemo</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
https://api.github.com/users/{username} Example: https://api.github.com/users/srikanthpragada
{ "login": "srikanthpragada", "id": 11234226, "avatar_url": "https://avatars0.githubusercontent.com/u/11234226?v=3", "gravatar_id": "", "url": "https://api.github.com/users/srikanthpragada", "html_url": "https://github.com/srikanthpragada", "followers_url": "https://api.github.com/users/srikanthpragada/followers", "following_url": "https://api.github.com/users/srikanthpragada/following{/other_user}", "gists_url": "https://api.github.com/users/srikanthpragada/gists{/gist_id}", "starred_url": "https://api.github.com/users/srikanthpragada/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/srikanthpragada/subscriptions", "organizations_url": "https://api.github.com/users/srikanthpragada/orgs", "repos_url": "https://api.github.com/users/srikanthpragada/repos", "events_url": "https://api.github.com/users/srikanthpragada/events{/privacy}", "received_events_url": "https://api.github.com/users/srikanthpragada/received_events", "type": "User", "site_admin": false, "name": "Srikanth Pragada", "company": "Srikanth Technologies", "blog": "http://www.srikanthtechnologies.com", "location": "Visakhapatnam, Andhra Pradesh, India", "email": "srikanthpragada@gmail.com", "hireable": null, "bio": null, "public_repos": 42, "public_gists": 1, "followers": 89, "following": 0, "created_at": "2015-02-27T18:37:39Z", "updated_at": "2017-03-09T16:31:41Z" }
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class GitHubUser { private String login, email, company, location, created_at; public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getCompany() { return company; } public void setCompany(String company) { this.company = company; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public String getCreated_at() { return created_at; } public void setCreated_at(String created_at) { this.created_at = created_at; } }
import org.springframework.web.client.RestTemplate; public class GetGitHubUserInfo { public static void main(String[] args) { RestTemplate restTemplate = new RestTemplate(); GitHubUser user = restTemplate.getForObject("https://api.github.com/users/srikanthpragada", GitHubUser.class); System.out.println("Login : " + user.getLogin()); System.out.println("Email : " + user.getEmail()); System.out.println("Company : " + user.getCompany()); System.out.println("Location: " + user.getLocation()); System.out.println("Created : " + user.getCreated_at()); } }
Login : srikanthpragada Email : srikanthpragada@gmail.com Company : Srikanth Technologies Location: Visakhapatnam, Andhra Pradesh, India Created : 2015-02-27T18:37:39Z
https://api.github.com/users/{user}/repos Example: https://api.github.com/users/srikanthpragada/repos
[ { "id": 50039390, "name": "android", "full_name": "srikanthpragada/android", "owner": { "login": "srikanthpragada", "id": 11234226, "avatar_url": "https://avatars0.githubusercontent.com/u/11234226?v=3", "gravatar_id": "", "url": "https://api.github.com/users/srikanthpragada", // other details }, "private": false, "html_url": "https://github.com/srikanthpragada/android", "description": "Android Programs", // other details }, { "id": 59585248, "name": "android_code", "full_name": "srikanthpragada/android_code", "owner": { "login": "srikanthpragada", "id": 11234226, "avatar_url": "https://avatars0.githubusercontent.com/u/11234226?v=3", "gravatar_id": "", "url": "https://api.github.com/users/srikanthpragada", // other details }, "private": false, "html_url": "https://github.com/srikanthpragada/android_code", "description": "Android Code Examples", // other details } // remaining details of other repos ]
import java.util.LinkedHashMap; import java.util.List; import org.springframework.web.client.RestTemplate; public class ListUserRepos { public static void main(String[] args) { RestTemplate restTemplate = new RestTemplate(); List<LinkedHashMap<String,String>> repos = restTemplate.getForObject("https://api.github.com/users/srikanthpragada/repos", List.class); for(LinkedHashMap<String,String> repo : repos) { System.out.println(repo.get("name")); } } }
android android_code android_device_features android_feb_2 android_storage angularjs angular_22_jan csharp c_june3_2016 c_language dec_1_javaee dec_1_javaee_web dec_22_csharpdemo dec_22_mvcdemo dec_22_webdemo feb20_webdemo feb_19_springcore feb_19_springmvc First hibernate_demo javaee javascript javase jdbc jQuery jsf june13_mvcdemo june13_webdemo june20_webdemo maven_restdemo