I have various data published by RESAS API, It's hard to get the data.
And once I made it, I thought it would be more convenient to share it with everyone. just made it. And I published it on github, but I can not find it so much, so I made an article.
RESAS-Client Java It is posted on github, so please git clone it from here or download it as a zip and use it.
https://github.com/code4nagoya/resas-client
https://opendata.resas-portal.go.jp/docs/api/v1/index.html https://opendata.resas-portal.go.jp/docs/api/v1/detail/index.html
Each class has a Request and a Result, and a test class. It's a test class, and I've just seen myself test it by hand. Please as a sample (Please note that some test classes are organized, Sumanu (-people-;))
It has a name along the URL and a class like Request / Result / RequetTest.
If you want to get the data from the API of the number of inland fishing boats, the URL will be as follows.
Since the class name is created according to the URL, the class is named FisheryRiverBoatForStacked ***.
In the *** part, the class with the parameters for sending is Request, and the class with the parameters for receiving is Result.
-Class with HTTP request parameters FisheryRiverBoatForStackedRequest -Received class FisheryRiverBoatForStackedResult -Send class used in the test FisheryRiverBoatForStackedRequestTest
To send, use the following class.
Class that makes a request for ResasHttpAccess http Pass the Request url and parameters to sendString. There is a place to write the API key in this class, but at runtime, pass it as a java argument in the form of -DXPIKEY = ******.
Class that sets the ResasUtil parameter Pass the parameter name and value listed in Request to Request respectively.
Have me git clone Take a look at the FisheryRiverBoatForStackedRequestTest.
There is a sample in the test class, so please take a look. The following is an excerpt.
python
@Test
public void test() throws ParseException, IOException {
ObjectMapper om = new ObjectMapper();
List<String> paramNames = new ArrayList<String>();
paramNames.add("prefCode");
List<String> paramValues = new ArrayList<String>();
paramValues.add("1");
StringBuffer params = ResasUtil.addParameters(paramNames, paramValues);
String result = ResasHttpAccess.sendString("api/v1" + FisheryRiverBoatForStackedRequest.url, params.toString());
System.out.println(result);
FisheryRiverBoatForStackedResult resultData = om.readValue(result,
FisheryRiverBoatForStackedResult.class);
FisheryRiverBoatForStacked a = resultData.getResult();
}
There is a general class, so please use it. Also, there are still many things that can be abstracted and easily done, so we look forward to your requests and help.
(゜ ∀ ゜) I hope the local area will be a wonderful city
Recommended Posts