LoginSignup
3
6

More than 5 years have passed since last update.

Spring Boot:Restful APIサンプルプロジェクト

Last updated at Posted at 2018-07-07

Spring Bootを使ってRestful APIを実装してみました。
ソースコード:https://github.com/unhurried/spring-boot-rest-api

ライブラリ

利用しているライブラリは以下の通り。

EclipseでAPIを起動する方法

  • DBMS(MySQL)と DBスキーマを用意する。
    • MySQLサーバーをインストールする。
    • /src/main/resources/application.yaml にMySQLサーバーの接続情報を記載する。
    • /sql/create.sql を実行してDBスキーマを作成する。
  • EclipseにSpring Tool Suiteをインストールする。
  • Eclipseにプロジェクトをインポートする。
    • ファイルインポート既存プロジェクトをワークスペースへ
  • パッケージ・エクスプローラーのApplication.javaを右クリック → 実行Spring Bootアプリケーション

APIリクエスト・レスポンス

ToDoリソースに対してCRUD操作を行うAPIが実装されている。

# Create a ToDo item.
$ curl --request POST \
>  --url http://localhost:8080/example/api/todos \
>  --header 'Content-Type: application/json' \
>  --data '{"title":"Test","content":"This is a test.","date": "2018-06-01"}' \
>  --include

HTTP/1.1 200
Content-Type: application/json
Content-Length: 71

{"id":1,"title":"Test","content":"This is a test.","date":"2018-06-01"}
3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6