CS 340 Milestone Two Guidelines and Rubric
Overview: For this assignment, you will implement a basic RESTful web service using either Python or Java. You will use the language-specific web services
framework to implement the RESTful service. You will later build upon this simple RESTful service implementation for your final project. Make sure you are using
the same programming language you chose in Module Four, as this assignment will build on the work you completed for Milestone One.
Reminders
•
•
Make sure you complete either the Java or the Python REST service tutorial in your Codio
terminal before you start this assignment.
Type all Python code into your Codio terminal manually, especially when running the
Python example code below. Python is space-sensitive and does not copy into the Codio
terminal well.
Prior to completing the prompt for this assignment, run the following code in your chosen language.
Create a basic web service using the RESTful design pattern to implement the following URI example:
http://localhost/currentTime
The above URI should return the current server system time in the following JSON format text:
{ date : MM-DD-YYYY , time : HH:MM:SS }
Example Python Code
#!/usr/bin/python
import json
from bson import json_util
import bottle
from bottle import route, run, request, abort
# set up URI paths for REST service
@route('/currentTime', method='GET')
def get_currentTime():
dateString=datetime.datetime.now().strftime("%Y-%m-%d")
timeString=datetime.datetime.now().strftime("%H:%M:%S")
string="{\"date\":"+dateString+",\"time\":"+timeString+"}"
return json.loads(json.dumps(string, indent=4, default=json_util.default))
if __name__ == '__main__':
#app.run(debug=True)
run(host='localhost', port=8080)
Example Java Code Using Spring.io Framework
Application.java:
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
GreetingController.java
package hello;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
}
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
@RequestMapping("/currentTime")
public Greeting greeting() {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd HH:mm");
String sdt = df.format(new Date(System.currentTimeMillis()));
return new Greeting(counter.incrementAndGet(),
sdt);
}
Greeting.java
package hello;
public class Greeting {
private final long id;
private final String content;
public Greeting(long id, String content) {
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
Prompt: After reviewing the module resources, complete the following tasks in Codio:
1. Create a basic web service using the RESTful design pattern to implement the following URIs:
a. http://localhost/hello?name=”world”
The above URI should return the following JSON-format text:
{ hello: “world” }
b. HTTP POST the JSON data: {string1:”hello”, string2:”world”} to http://localhost/strings
The above URI should return the following JSON-format text:
{ first: “hello”, second: “world” }
Provide a text file (either .java or .py) of your code and screenshots of execution as evidence. You will use the curl utility at the Codio command line to
execute the URI. See the examples below.
HTTP Action
Operation
Curl Example
Possible HTTP Response Codes
GET
Read
curl
http://localhost:8080/hello?name=”world”
200 OK, 404 Not Found
POST
Create
curl -H "Content-Type: application/json" -X
POST -d '{"string1":"hello","string2":"world"}'
http://localhost:8080/strings
200 OK, 404 Not Found
2. Using the RESTful web service you created in Step 1, add URI paths to the RESTful service for each of your CRUD functions completed in Milestone One.
Your URI paths should be able to handle the following curl client interactions:
"Add the following document to the collection:"
curl -H "Content-Type: application/json" -X POST -d '{"id" : "10011-2017-TEST","certificate_number" : 9278833,"business_name" : “ACME TEST
INC.","date" : "Feb 20 2017","result" : "No Violation Issued","sector" : "Test Retail Dealer - 101"}' http://localhost:8080/create
"Return the document found with the given business_name"
curl http://localhost:8080/read?business_name="ACME TEST INC."
"Update the result value for the document with the given id string"
curl http://localhost:8080/update?id="10011-2017-TEST"&result="Violation Issued"
"Delete the document with the given id string"
curl http://localhost:8080/delete?id="10011-2017-TEST"
Provide a text file (either .java or .py) of your code.
Specifically, the following must be addressed in your submission:
●
RESTful Web Service Using Either Python or Java Programming Language: Use your code submission and screenshots to demonstrate web service
interactions.
Rubric
Guidelines for Submission: You must submit two files for this assignment:
•
•
A Microsoft Word document (or equivalent) with double spacing, 12-point Times New Roman font, one-inch margins, and the appropriate screenshots
A text file (either .java or .py) of your code
Critical Elements
Hello World GET
Proficient (100%)
Creates RESTful web service and
implements GET URI
Hello World String POST
Creates RESTful web service and
implements POST URI
RESTful Service for Create
Creates RESTful web service and adds
URI path for create function
Needs Improvement (75%)
Creates RESTful web service and
implements GET URI, but result lacks
accuracy or appropriate functionality
Creates RESTful web service and
implements POST URI, but result lacks
accuracy or appropriate functionality
Creates RESTful web service and adds
URI path for create function, but result
lacks accuracy or appropriate
functionality
Not Evident (0%)
Does not create RESTful web service or
implement GET URI
Value
10
Does not create RESTful web service or
implement POST URI
10
Does not create RESTful web service or
add URI path for create functionality
20
RESTful Service for Read
Creates RESTful web service and adds
URI path for read function
RESTful Service for Update
Creates RESTful web service and adds
URI path for update function
RESTful Service for Delete
Creates RESTful web service and adds
URI path for delete function
Creates RESTful web service and adds
URI path for read function, but result
lacks accuracy or appropriate
functionality
Creates RESTful web service and adds
URI path for update function, but result
lacks accuracy or appropriate
functionality
Creates RESTful web service and adds
URI path for delete function, but result
lacks accuracy or appropriate
functionality
Does not create RESTful web service or
add URI path for read functionality
20
Does not create RESTful web service or
add URI path for update functionality
20
Does not create RESTful web service or
add URI path for delete functionality
20
Total
100%
Purchase answer to see full
attachment