由于辞职的原因,最近正在忙于找工作。在这段期间收到了一家公司的上机测试题,一共两道题,其中一道题是关于REST API的应用。
什么是REST? 在此不详说。我说一下自己的理解吧。简单地说,REST就是一种基于HTTP请求服务从而达到操作资源的技术,其支持多种数据格式,比如xml、Json、Csv等等。Web Service是基本XML并利用SOAP协议实现远程资源访问操作的技术。因此,两者本质还是不同的。也许我的理解不完全正确,欢迎指出错误。
下面来看看这道题,如下:
Userstory:
As a user I want to be able to see maximum, minimum and average predicted temperature for the following 3 days,
based on the city that needs to be entered.
Acceptance criteria:
Windows form application written in C#
One input field to define the city
A combobox to select Fahrenheit or Celcius degrees
Use free web service provided by http://www.worldweatheronline.com
The following key can be used to retrieve data : c6bbde7c9c021451123107
Show 'Retrieving weather data...' in status bar when request of data is submitted. Once data is retrieved
update status accordingly.
Use of linq statements to calculate the minimum, maximum and average temperature.
Main form needs to be responsive at all times
Use of delegates
Retrieval of data and UI logic needs to be seperated in code
Error handling when connection
以下是我写的代码: