{"id":15684069,"url":"https://github.com/jexp/sdn-twitter-graph","last_synced_at":"2025-05-07T15:07:46.605Z","repository":{"id":4094200,"uuid":"5202092","full_name":"jexp/sdn-twitter-graph","owner":"jexp","description":"A sample twitter-graph application written with Spring Data Neo4j","archived":false,"fork":false,"pushed_at":"2014-04-14T15:38:40.000Z","size":145,"stargazers_count":10,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T15:07:38.815Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jexp.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-07-27T08:06:35.000Z","updated_at":"2022-05-07T21:28:28.000Z","dependencies_parsed_at":"2022-08-26T22:41:09.786Z","dependency_job_id":null,"html_url":"https://github.com/jexp/sdn-twitter-graph","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jexp%2Fsdn-twitter-graph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jexp%2Fsdn-twitter-graph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jexp%2Fsdn-twitter-graph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jexp%2Fsdn-twitter-graph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jexp","download_url":"https://codeload.github.com/jexp/sdn-twitter-graph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252902614,"owners_count":21822261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T17:10:37.905Z","updated_at":"2025-05-07T15:07:46.585Z","avatar_url":"https://github.com/jexp.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntags: [spring-data, neo4j, rest, hateoas,twitter,social]\nprojects: [spring-data-rest,spring-data-neo4j,spring-social]\n---\n:spring_version: current\n:spring_data_rest: 2.0.0.RELEASE\n:spring_data_commons: 1.7.0.RELEASE\n:spring_boot_version: 1.0.0.RELEASE\n:Component: http://docs.spring.io/spring/docs/{spring_version}/javadoc-api/org/springframework/stereotype/Component.html\n:Controller: http://docs.spring.io/spring/docs/{spring_version}/javadoc-api/org/springframework/stereotype/Controller.html\n:DispatcherServlet: http://docs.spring.io/spring/docs/{spring_version}/javadoc-api/org/springframework/web/servlet/DispatcherServlet.html\n:SpringApplication: http://docs.spring.io/spring-boot/docs/{spring_boot_version}/api/org/springframework/boot/SpringApplication.html\n:ResponseBody: http://docs.spring.io/spring/docs/{spring_version}/javadoc-api/org/springframework/web/bind/annotation/ResponseBody.html\n:EnableAutoConfiguration: http://docs.spring.io/spring-boot/docs/{spring_boot_version}/api/org/springframework/boot/autoconfigure/EnableAutoConfiguration.html\n:toc:\n:icons: font\n:source-highlighter: prettify\n:project_id: sdn-twitter-graph\n\nThis guide walks you through the process of creating an application that accesses graph-based data through a link:/guides/gs/rest-hateoas[hypermedia-based] link:/understanding/REST[RESTful front end].\n\n== What you'll build\n\nYou'll build a Spring application that uses http://projects.spring.io/spring-social/[Spring Social] to fetch Tweets according to a defined search. It stores the Tweets, Tags, Users via http://projects.spring.io/spring-data-neo4j[Spring Data Neo4j] in a Neo4j graph database and let's you retrieve (and create) those objects using Spring Data REST. Spring Data REST takes the features of http://projects.spring.io/spring-hateoas[Spring HATEOAS] and http://projects.spring.io/spring-data-neo4j[Spring Data Neo4j] and combines them together automatically.\n\nThe domain looks like this:\n\nimage:\n\n== What you'll need\n\ninclude::https://raw.github.com/spring-guides/getting-started-macros/master/prereq_editor_jdk_buildtools.adoc[]\n\ninclude::https://raw.github.com/spring-guides/getting-started-macros/master/how_to_complete_this_guide.adoc[]\n\n\n[[scratch]]\n== Set up the project\n\ninclude::https://raw.github.com/spring-guides/getting-started-macros/master/build_system_intro.adoc[]\n\ninclude::https://raw.github.com/spring-guides/getting-started-macros/master/create_directory_structure_hello.adoc[]\n\ninclude::https://raw.github.com/spring-guides/getting-started-macros/master/create_both_builds.adoc[]\n\n`build.gradle`\n// AsciiDoc source formatting doesn't support groovy, so using java instead\n[source,java]\n----\ninclude::initial/build.gradle[]\n----\n\ninclude::https://raw.github.com/spring-guides/getting-started-macros/master/spring-boot-gradle-plugin.adoc[]\n\n\n[[initial]]\n== Create a domain object\n\nCreate a new domain object to present a twitter user.\n\n`src/main/java/org/neo4j/twitter_graph/domain/User.java`\n[source,java]\n----\ninclude::complete/src/main/java/org/neo4j/twitter_graph/domain/User.java[]\n----\n\nThe `Person` has a first name and a last name. There is also an id object that is configured to be automatically generated so you don't have to deal with that.\n\n== Create a Person repository\n\nNext you need to create a simple repository.\n\n`src/main/java/hello/PersonRepository.java`\n[source,java]\n----\ninclude::complete/src/main/java/hello/PersonRepository.java[]\n----\n\nThis repository is an interface and will allow you to perform various operations involving `Person` objects. It gets these operations by extending the http://docs.spring.io/spring-data/commons/docs/{spring_data_commons}/api/org/springframework/data/repository/PagingAndSortingRepository.html[PagingAndSortingRepositry] interface defined in Spring Data Commons.\n\nAt runtime, Spring Data REST will create an implementation of this interface automatically. Then it will use the http://docs.spring.io/spring-data/rest/docs/{spring_data_rest}/api/org/springframework/data/rest/core/annotation/RepositoryRestResource.html[@RepositoryRestResource] annotation to direct Spring MVC to create RESTful endpoints at `/people`.\n\n== Make the application executable\n\nAlthough it is possible to package this service as a traditional link:/understanding/WAR[WAR] file for deployment to an external application server, the simpler approach demonstrated below creates a standalone application. You package everything in a single, executable JAR file, driven by a good old Java `main()` method. Along the way, you use Spring's support for embedding the link:/understanding/Tomcat[Tomcat] servlet container as the HTTP runtime, instead of deploying to an external instance.\n\n\n`src/main/java/hello/Application.java`\n[source,java]\n----\ninclude::complete/src/main/java/hello/Application.java[]\n----\n\nThe `main()` method defers to the {SpringApplication}[`SpringApplication`] helper class, providing `Application.class` as an argument to its `run()` method. This tells Spring to read the annotation metadata from `Application` and to manage it as a component in the link:/understanding/application-context[Spring application context].\n\nThe `@EnableNeo4jRepositories` annotation activates Spring Data Neo4j. Spring Data Neo4j will create a concrete implementation of the `PersonRepository` and configure it to talk to an embedded Neo4j database using the Cypher query language. Please make sure to set the base-package for your entities with `setBasePackage(packageNames)` in the constructor of your application.\n\nSpring Data REST is a Spring MVC application. The `@Import(RepositoryRestMvcConfiguration.class)` annotation imports a collection of Spring MVC controllers, JSON converters, and other beans needed to provide a RESTful front end. These components link up to the Spring Data Neo4j backend.\n\nThe {EnableAutoConfiguration}[`@EnableAutoConfiguration`] annotation switches on reasonable default behaviors based on the content of your classpath. For example, because the application depends on the embeddable version of Tomcat (tomcat-embed-core.jar), a Tomcat server is set up and configured with reasonable defaults on your behalf. And because the application also depends on Spring MVC (spring-webmvc.jar), a Spring MVC {DispatcherServlet}[`DispatcherServlet`] is configured and registered for you — no `web.xml` necessary! Auto-configuration is a powerful, flexible mechanism. See the {EnableAutoConfiguration}[API documentation] for further details.\n\ninclude::https://raw.github.com/spring-guides/getting-started-macros/master/build_an_executable_jar_subhead.adoc[]\n\ninclude::https://raw.github.com/spring-guides/getting-started-macros/master/build_an_executable_jar_with_both.adoc[]\n\n:module: service\ninclude::https://raw.github.com/spring-guides/getting-started-macros/master/run_the_application_with_both.adoc[]\n\nLogging output is displayed. The service should be up and running within a few seconds.\n\n\n== Test the application\n\nNow that the application is running, you can test it. You can use any REST client you wish. The following examples use the *nix tool `curl`.\n\nFirst you want to see the top level service.\n\n```\n$ curl http://localhost:8080\n{\n  \"_links\" : {\n    \"people\" : {\n      \"href\" : \"http://localhost:8080/people{?page,size,sort}\",\n      \"templated\" : true\n    }\n  }\n}\n```\n\nHere you get a first glimpse of what this server has to offer. There is a **people** link located at http://localhost:8080/people. It has some options such as `?page`, `?size`, and `?sort`.\n\nNOTE: Spring Data REST uses the http://stateless.co/hal_specification.html[HAL format] for JSON output. It is flexible and offers a convenient way to supply links adjacent to the data that is served.\n\n```\n$ curl http://localhost:8080/people\n{\n  \"_links\" : {\n    \"self\" : {\n      \"href\" : \"http://localhost:8080/people{?page,size,sort}\",\n      \"templated\" : true\n    }\n  },\n  \"page\" : {\n    \"size\" : 20,\n    \"totalElements\" : 0,\n    \"totalPages\" : 0,\n    \"number\" : 0\n  }\n}\n```\n\nThere are currently no elements and hence no pages. Time to create a new `Person`!\n\n```\n$ curl -i -X POST -H \"Content-Type:application/json\" -d '{  \"firstName\" : \"Frodo\",  \"lastName\" : \"Baggins\" }' http://localhost:8080/people\nHTTP/1.1 201 Created\nServer: Apache-Coyote/1.1\nLocation: http://localhost:8080/people/1\nContent-Length: 0\nDate: Wed, 26 Feb 2014 20:26:55 GMT\n```\n\n- `-i` ensures you can see the response message including the headers. The URI of the newly created `Person` is shown\n- `-X POST` signals this a POST used to create a new entry\n- `-H \"Content-Type:application/json\"` sets the content type so the application knows the payload contains a JSON object\n- `-d '{  \"firstName\" : \"Frodo\",  \"lastName\" : \"Baggins\" }'` is the data being sent\n\nFrom this you can query against for all people:\n\n```\n$ curl http://localhost:8080/people\n{\n  \"_links\" : {\n    \"self\" : {\n      \"href\" : \"http://localhost:8080/people{?page,size,sort}\",\n      \"templated\" : true\n    }\n  },\n  \"_embedded\" : {\n    \"persons\" : [ {\n      \"firstName\" : \"Frodo\",\n      \"lastName\" : \"Baggins\",\n      \"_links\" : {\n        \"self\" : {\n          \"href\" : \"http://localhost:8080/people/1\"\n        }\n      }\n    } ]\n  },\n  \"page\" : {\n    \"size\" : 20,\n    \"totalElements\" : 1,\n    \"totalPages\" : 1,\n    \"number\" : 0\n  }\n}\n```\n\nThe **persons** object contains a list with Frodo. Notice how it includes a **self** link. Spring Data REST also uses http://www.atteo.org/2011/12/12/Evo-Inflector.html[Evo Inflector] to pluralize the name of the entity for groupings.\n\nYou can query directly for the individual record:\n\n```\n$ curl http://localhost:8080/people/1\n{\n  \"firstName\" : \"Frodo\",\n  \"lastName\" : \"Baggins\",\n  \"_links\" : {\n    \"self\" : {\n      \"href\" : \"http://localhost:8080/people/1\"\n    }\n  }\n}\n```\n\nNOTE: This might appear to be purely web based, but behind the scenes, there is an embedded Neo4j graph database. In production, you would probably connect to a stand alone Neo4j server.\n\nIn this guide, there is only one domain object. With a more complex system where domain objects are related to each other, Spring Data REST will render additional links to help navigate to connected records.\n\nYou can also issue PUT, PATCH, and DELETE REST calls to either replace, update, or delete existing records.\n\n```\n$ curl -X PUT -H \"Content-Type:application/json\" -d '{ \"firstName\": \"Bilbo\", \"lastName\": \"Baggins\" }' http://localhost:8080/people/1\n$ curl http://localhost:8080/people/1\n{\n  \"firstName\" : \"Bilbo\",\n  \"lastName\" : \"Baggins\",\n  \"_links\" : {\n    \"self\" : {\n      \"href\" : \"http://localhost:8080/people/1\"\n    }\n  }\n}\n```\n\n```\n$ curl -X PATCH -H \"Content-Type:application/json\" -d '{ \"firstName\": \"Bilbo Jr.\" }' http://localhost:8080/people/1\n$ curl http://localhost:8080/people/1\n{\n  \"firstName\" : \"Bilbo Jr.\",\n  \"lastName\" : \"Baggins\",\n  \"_links\" : {\n    \"self\" : {\n      \"href\" : \"http://localhost:8080/people/1\"\n    }\n  }\n}\n```\n\nNOTE: PUT replaces an entire record. Fields not supplied will be replaced with null. PATCH can be used to update a subset of items.\n\nYou can delete records:\n\n```\n$ curl -X DELETE http://localhost:8080/users/1\n$ curl http://localhost:8080/users\n{\n  \"_links\" : {\n    \"self\" : {\n      \"href\" : \"http://localhost:8080/people{?page,size,sort}\",\n      \"templated\" : true\n    }\n  },\n  \"page\" : {\n    \"size\" : 20,\n    \"totalElements\" : 0,\n    \"totalPages\" : 0,\n    \"number\" : 0\n  }\n}\n```\n\n== Summary\n\nCongratulations! You've just developed an application with a link:/guides/gs/rest-hateoas[hypermedia-based] link:/understanding/REST[RESTful] front end and a Neo4j-based back end.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjexp%2Fsdn-twitter-graph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjexp%2Fsdn-twitter-graph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjexp%2Fsdn-twitter-graph/lists"}