{"id":17999088,"url":"https://github.com/wkrzywiec/library-api","last_synced_at":"2025-03-26T06:31:30.824Z","repository":{"id":111645854,"uuid":"148584080","full_name":"wkrzywiec/Library-API","owner":"wkrzywiec","description":"A REST API for my other project - Library Spring","archived":false,"fork":false,"pushed_at":"2018-10-12T17:02:15.000Z","size":186,"stargazers_count":3,"open_issues_count":0,"forks_count":5,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-21T08:48:40.238Z","etag":null,"topics":["actuator","app-engine","cloud-sql","crud","flyway","google-cloud-platform","gradle","hateoas","jackson","java-8","jetty-server","json","library-management-system","mysql","rest-api","restful-webservices","spring-boot","swagger-ui","swagger2","webservice"],"latest_commit_sha":null,"homepage":"","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/wkrzywiec.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-13T04:57:42.000Z","updated_at":"2023-02-02T01:13:51.000Z","dependencies_parsed_at":"2023-05-24T21:30:25.524Z","dependency_job_id":null,"html_url":"https://github.com/wkrzywiec/Library-API","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/wkrzywiec%2FLibrary-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wkrzywiec%2FLibrary-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wkrzywiec%2FLibrary-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wkrzywiec%2FLibrary-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wkrzywiec","download_url":"https://codeload.github.com/wkrzywiec/Library-API/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245603756,"owners_count":20642873,"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":["actuator","app-engine","cloud-sql","crud","flyway","google-cloud-platform","gradle","hateoas","jackson","java-8","jetty-server","json","library-management-system","mysql","rest-api","restful-webservices","spring-boot","swagger-ui","swagger2","webservice"],"created_at":"2024-10-29T22:09:58.557Z","updated_at":"2025-03-26T06:31:30.805Z","avatar_url":"https://github.com/wkrzywiec.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Library-API\r\nThis a simple REST service and is part of the other project - [Library Portal](https://github.com/wkrzywiec/Library-Spring) (web application). It allows to perform CRUD actions on basic resources, like users or books entities, and retrieve them as JSON respond.\r\n\r\nSimilarly to the main project, it contains Flyway migration scripts so MySQL database could be set up regardless of the main app.\r\n\r\nThere is also a different version of this app that can be deployed and ran on the Google Cloud Platform service - [Google App Engine](https://cloud.google.com/appengine/) and [Cloud SQL](https://cloud.google.com/sql/). To see the source code go to another branch of this repository called [app-engine](https://github.com/wkrzywiec/Library-API/tree/app-engine).\r\n\r\n## How to run?\r\n\r\nFirst create a new user and schema in you local database.\r\n\r\n```sql\r\n  CREATE USER 'library-spring'@'localhost' IDENTIFIED BY 'library-spring';\r\n  GRANT ALL PRIVILEGES ON  *.* TO 'library-spring'@'localhost';\r\n  SET GLOBAL EVENT_SCHEDULER = ON;\r\n  \r\n  CREATE SCHEMA `library_db`\r\n```\r\n\r\nNext, clone this repository.\r\n\r\n```\r\n$ git clone https://github.com/wkrzywiec/Library-Spring\r\n```\r\n\r\nFinally run this application thru LibraryRestApplication as Java application.\r\n\r\n```java\r\n@SpringBootApplication\r\npublic class LibraryRestApplication {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSpringApplication.run(LibraryRestApplication.class, args);\r\n\t}\r\n}\r\n```\r\n\r\n## Documentation\r\n### Swagger 2\r\nFor rendering the documentation of the API Swagger 2 with Springfox implementation was used. \r\n\r\nWhen the application is running, type in a browser:\r\n\r\n```\r\nhttp://localhost:8888/library-spring/api/v2/api-docs\r\n```\r\nTo receive such respond (only part)\r\n\r\n```json\r\n{\r\n\t\"swagger\": \"2.0\",\r\n\t\"info\": {\r\n\t\t\"description\": \"This a simple REST service and is part of the other project - Library Portal. It allows to perform CRUD actions on basic resources, like users or books entities, and retrieve them as a JSON respond.\",\r\n\t\t\"version\": \"1.0\",\r\n\t\t\"title\": \"Library Portal API\",\r\n\t\t\"termsOfService\": \"urn:tos\",\r\n\t\t\"contact\": {\r\n\t\t\t\"name\": \"Wojciech Krzywiec\",\r\n\t\t\t\"url\": \"https://github.com/wkrzywiec\"\r\n\t\t},\r\n\t\t\"license\": {\r\n\t\t\t\"name\": \"Apache 2.0\",\r\n\t\t\t\"url\": \"http://www.apache.org/licenses/LICENSE-2.0:\"\r\n\t\t}\r\n\t},\r\n\t\"host\": \"localhost:8888\",\r\n\t\"basePath\": \"/library-spring/api\",\r\n\t\"tags\": [],\r\n\t\"paths\": {},\r\n\t\"definitions\": {\r\n\t\t\"Author\": {\r\n\t\t\t\"type\": \"object\",\r\n\t\t\t\"properties\": {\r\n\t\t\t\"id\": {\r\n\t\t\t\t\"type\": \"integer\",\r\n\t\t\t\t\"format\": \"int64\"\r\n\t\t\t},\r\n\t\t\t\"name\": {\r\n\t\t\t\t\"type\": \"string\"\r\n\t\t\t}\r\n\t\t\t},\r\n\t\t\t\"title\": \"Author\"\r\n\t\t},\r\n```\r\nAlso [Swagger UI](https://swagger.io/tools/swagger-ui/) is supported, to enter it type in a browser:\r\n\r\n```\r\nhttp://localhost:8888/library-spring/api/swagger-ui.html\r\n```\r\n### Resources\r\n\r\nBase URL for each request is `https://localhost:8888//library-spring/api`, so combine it with one of the following parts.\r\n#### User\r\n\r\n| Link          | HTTP Method   | Description                                        | \r\n| ------------- | ------------- | -------------------------------------------------  |\r\n| `/users`      | GET           | Retrieve the list of all users.                    |\r\n| `/users/{id}` | GET           | Retrieve specific user with provided `{id}`.    |\r\n| `/users`      | POST          | Add new user to the database.                      |\r\n| `/users/{id}` | PUT           | Update specific user's (`{id}`) fields.           |\r\n| `/users/{id}` | DELETE        | Delete from the database user with provided `{id}`. |\r\n\r\nSample JSON respond of the user resource.\r\n\r\n```json\r\n{\r\n\t\"id\": 17,\r\n\t\"username\": \"daenerys\",\r\n\t\"email\": \"denerys.targaryen@kings-landing.com\",\r\n\t\"enable\": true,\r\n\t\"firstName\": \"Daenerys\",\r\n\t\"lastName\": \"Targaryen\",\r\n\t\"phone\": null,\r\n\t\"birthday\": null,\r\n\t\"address\": null,\r\n\t\"postalCode\": null,\r\n\t\"city\": null,\r\n\t\"recordCreated\": \"2018-09-27T06:37:54.000+0000\",\r\n\t\"roles\": [\r\n\t\t{\r\n\t\t\"id\": 1,\r\n\t\t\"name\": \"USER\"\r\n\t\t}\r\n\t],\r\n\t\"_links\": {\r\n\t\"self\": {\r\n\t\t\"href\": \"http://localhost:8888/library-spring/api/users/17\"\r\n\t\t},\r\n\t\t\"users\": {\r\n\t\t\"href\": \"http://localhost:8888/library-spring/api/users\"\r\n\t\t}\r\n\t}\r\n}\r\n\r\n```\r\n\r\n#### Book\r\n\r\n| Link          | HTTP Method   | Description                                        | \r\n| ------------- | ------------- | -------------------------------------------------  |\r\n| `/books`      | GET           | Retrieve the list of all books.                    |\r\n| `/books/{id}` | GET           | Retrieve specific book with provided `{id}`.    \t|\r\n| `/books/{id}` | DELETE         | Delete from the database book with provided `{id}`.    \t|\r\n\r\nSample JSON respond of the book resource.\r\n\r\n```json\r\n{\r\n\t\"id\": 6,\r\n\t\"googleId\": \"5NomkK4EV68C\",\r\n\t\"title\": \"A Game of Thrones\",\r\n\t\"authors\": [\r\n\t\t{\r\n\t\t\t\"id\": 6,\r\n\t\t\t\"name\": \"George R. R. Martin\"\r\n\t\t}\r\n\t],\r\n\t\"publisher\": \"Random House Publishing Group\",\r\n\t\"publishedDate\": \"2003-01-01\",\r\n\t\"isbn\": {\r\n\t\t\"id\": 6,\r\n\t\t\"isbn10\": \"0553897845\",\r\n\t\t\"isbn13\": \"9780553897845\"\r\n\t},\r\n\t\"pageCount\": 720,\r\n\t\"categories\": [\r\n\t\t{\r\n\t\t\t\"id\": 1,\r\n\t\t\t\"name\": \"Fiction / Action \u0026 Adventure\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"id\": 11,\r\n\t\t\t\"name\": \"Fiction / Science Fiction / Action \u0026 Adventure\"\r\n\t\t},\r\n\t\t{\r\n\t\t\"id\": 12,\r\n\t\t\"name\": \"Fiction / Fantasy / Epic\"\r\n\t\t}\r\n\t],\r\n\t\"rating\": 4,\r\n\t\"imageLink\": \"http://books.google.com/books/content?id=5NomkK4EV68C\u0026printsec=frontcover\u0026img=1\u0026zoom=1\u0026edge=curl\u0026imgtk=AFLRE72NMsHhHG15TMsLXMP_WEUjVBNIr6BQ7m8dvfjDiT6wLCw2QcIXGE4nQdaKFJnWgu2INjLeAxmWg5hnq5GyKW7b-u0mtGnGIdc2GWdBa-LSp118g0Ug4H-8OKFS1qXSOtQxxcZc\u0026source=gbs_api\",\r\n\t\"description\": \"A SONG OF ICE AND FIRE: BOOK ONE...\",\r\n\t\"_links\": {\r\n\t\t\"self\": {\r\n\t\t\t\"href\": \"http://localhost:8888/library-spring/api/books/6\"\r\n\t\t},\r\n\t\t\"books\": {\r\n\t\t\t\"href\": \"http://localhost:8888/library-spring/api/books\"\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n#### Reserved\r\n\r\n| Link          | HTTP Method   | Description                                        | \r\n| ------------- | ------------- | -------------------------------------------------  |\r\n| `/reserved`     | GET         | Retrieve the list of all reservations.             |\r\n| `/reserved/{id}`| GET         | Retrieve specific reservation with provided `{id}`.    |\r\n| `/reserved/users/{userId}`   | GET         | Retrieve list of reservations that are assigned to the user `{userId}`. |\r\n| `/reserved/books/{bookId}`   | GET         | Retrieve reservation resource that is assigned to the book `{bookId}`.|\r\n\r\n\r\n#### Borrowed\r\n\r\n| Link          | HTTP Method   | Description                                        | \r\n| ------------- | ------------- | -------------------------------------------------  |\r\n| `/borrowed`     | GET         | Retrieve the list of all borrowed books.             |\r\n| `/borrowed/{id}`| GET         | Retrieve specific borrowed book with provided `{id}`.    |\r\n| `/borrowed/users/{userId}`   | GET         | Retrieve list of borrowed books that are assigned to the user `{userId}`. |\r\n| `/borrowed/books/{bookId}`   | GET         | Retrieve borrowed resource that is assigned to the book `{bookId}`.|\r\n\r\n\r\n## Monitoring\r\nLibrary API has also several monitoring endpoints enabled. After typing following address in a web browser\r\n\r\n```\r\nhttp://localhost:8888/library-spring/api/actuator/\r\n```\r\nYou should get the list of links. Each of them provides useful information about running application.\r\n\r\n```json\r\n{\r\n\t\"_links\": {\r\n\t\t\"self\": {\r\n\t\t\t\"href\": \"http://localhost:8888/library-spring/api/actuator\",\r\n\t\t\t\"templated\": false\r\n\t\t},\r\n\t\t\"health\": {\r\n\t\t\t\"href\": \"http://localhost:8888/library-spring/api/actuator/health\",\r\n\t\t\t\"templated\": false\r\n\t\t},\r\n\t\t\"flyway\": {\r\n\t\t\t\"href\": \"http://localhost:8888/library-spring/api/actuator/flyway\",\r\n\t\t\t\"templated\": false\r\n\t\t},\r\n\t\t\"info\": {\r\n\t\t\t\"href\": \"http://localhost:8888/library-spring/api/actuator/info\",\r\n\t\t\t\"templated\": false\r\n\t\t},\r\n\t\t\"loggers\": {\r\n\t\t\t\"href\": \"http://localhost:8888/library-spring/api/actuator/loggers\",\r\n\t\t\t\"templated\": false\r\n\t\t},\r\n\t\t\"loggers-name\": {\r\n\t\t\t\"href\": \"http://localhost:8888/library-spring/api/actuator/loggers/{name}\",\r\n\t\t\t\"templated\": true\r\n\t\t},\r\n\t\t\"httptrace\": {\r\n\t\t\t\"href\": \"http://localhost:8888/library-spring/api/actuator/httptrace\",\r\n\t\t\t\"templated\": false\r\n\t\t},\r\n\t\t\"mappings\": {\r\n\t\t\t\"href\": \"http://localhost:8888/library-spring/api/actuator/mappings\",\r\n\t\t\t\"templated\": false\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n## Technology stack\r\n\r\n- Java 8\r\n- Spring Boot \r\n- Hibernate, JPA\r\n- Swagger\r\n- JSON\r\n- HATEOAS\r\n- MySQL\r\n- Flyway\r\n- Tomcat server (only for local deployment)\r\n- Jetty server (only for Google Cloud Platform deployment)\r\n- Lombok\r\n- JUnit\r\n- Hamcrest\r\n\r\n## Useful links\r\n\r\n- [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/)\r\n- [Postman](https://www.getpostman.com/)\r\n- [Setting Up Swagger 2 with a Spring REST API](https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api)\r\n- [Spring Boot Actuator: Health check, Auditing, Metrics gathering and Monitoring](https://www.callicoder.com/spring-boot-actuator/)\r\n- [Tired of Null Pointer Exceptions? Consider Using Java SE 8's Optional!](https://www.oracle.com/technetwork/articles/java/java8-optional-2175753.html)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwkrzywiec%2Flibrary-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwkrzywiec%2Flibrary-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwkrzywiec%2Flibrary-api/lists"}