BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

C语言代写 | 3010-iji front-end processing API server

C语言代写 | 3010-iji front-end processing API server

本次美国代写主要为C语言相关的assignment

Frontend HTML page

Create a website that is hosted on your CS unix homepage that is a 3010-iji system. The web page should never refresh. Use XHR requests to fetch posts.

You must use XMLHttpRequest directly, not using fetch, or any libraries to do the data requests for you.

Use JSON to transfer all of the required information. You can use any structure for storing the data on the server, such as simple files, JSON, sqlite3, etc.

Use server-side processing as you deem necessary but note that you will be marked based on your overall design (excessive and unnecessary JavaScript will result in a loss of marks).

Backend API server

Paths:

  • GET / – return the above HTML page
  • GET /posts – gets all posts
  • GET /posts/post_id – gets full text of 1 post
  • DELETE /posts/post_id – Deletes a post
  • POST /posts – adds a post to the system

Notes:

  • All socket programming will be done without any advanced objects (such as SocketServer in Python); I want you to work with actual sockets here so you get a good idea how they work (you must use the system calls detailed in class). Any packages, frameworks, classes that provide any web/http related services or hide communications are not allowed.
  • The following Python packages can be used to complete this question: socket, time, json, sqlite3 and sys.
  • In order to ensure that you don’t use ports that are being used by someone else (e.g. a fellow student), you have all been assigned a unique port to use for the programs in this assignment. Please see for the Port Assignment module to find your port number.
  • Yes, you can use packages to do this. Part of the fun is being able to implement an http server, from scratch, on your own (if a Physicist can do it, so can you!).

Write an API server to be the backend for your 3010-iji client. Your client will open a stream socket, and listen for requests.

Your server should not crash, even given bad requests. It should give appropriate error message and HTTP statuses given bad data.

You may use any programming language, provided it can compile (if applicable) and run on the CS UNIX machines. Python is a good choice, but consider using Go.

Notes

Your POSTs will have a json body in your XHR request.

Javascript can convert to and from json.

From w3schools:

var myObj = {name: “John”, age: 31, city: “New York”};

var myJSON = JSON.stringify(myObj);

var myJSON = ‘{“name”:”John”, “age”:31, “city”:”New York”}’;

var myObj = JSON.parse(myJSON);

You can send a JSON body with XHR’s .send(), which can accept a parameter, which is a string.

XHR requests can set cookies. XHR requests send cookies if you set withCredentials on your object. You also must set withCredentials if you wish to SET cookies.

Python json library to convert from and to json.

Consider using “Insomnia Core” or “Postman” to test your API. These can be used to send HTTP requests to your API.

Sockets sent bytes. Create bytes with:

  • encode : requestSocket.send(body.encode())
  • b flag: requestSocket.send(b”HTTP/1.1 404 Not Found\n”)
  • casting to bytes()

You can test this part locally on your machine! We will test locally, if it does not work locally, we will test it on the aviary machines.

Bonus +50% of Part 2’s weight

Do part 2 API server in C.

bestdaixie

评论已关闭。