🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

CSC123 (INTRO TO PROGRAMMING II) Usman Aslam | Computer Science REST API REST stands for REpresentational State Transfer The API stands for Application Programming Interface if you write a reusable Java class with methods, you are essentially creating an API REST is an architectural style: That is u...

CSC123 (INTRO TO PROGRAMMING II) Usman Aslam | Computer Science REST API REST stands for REpresentational State Transfer The API stands for Application Programming Interface if you write a reusable Java class with methods, you are essentially creating an API REST is an architectural style: That is used to build scalable and distributed systems That enables interoperability Where resources are hosted on remote servers and are accessed using Uniform Resource Locator (URL) addresses Where the client makes requests to access and manipulate resources using methods such as GET, POST, PUT, PATCH, DELETE, etc. REST API WHY USE REST? Scalability: RESTful APIs can handle large numbers of requests from a wide range of clients Simplicity: REST is easy to understand and implement due to its adherence to standard HTTP methods (GET, POST, PUT, DELETE) Interoperability: Works well with different platforms, languages, and systems, promoting reusability and collaboration Performance: Stateless nature allows for better caching, reducing server load and improving response times Maintainability: Separation of concerns between client and server allows for independent development and updates JSON JSON stands for JavaScript Object Notation It is a lightweight data-interchange format that is easy for humans to read and write, and easy for machines to parse and generate. JSON is based on a subset of the JavaScript programming language, but is language-independent and can be used with any programming language that can parse JSON data. JSON data is structured as key-value pairs, where keys are strings and values can be strings, numbers, booleans, arrays, or other JSON objects JSON data can be easily converted to and from native data types in most programming languages using built-in functions or third-party libraries. JSON syntax is simple and flexible, allowing for comments, whitespace, and varying levels of data complexity. JSON is widely used in web development, mobile app development, and other software applications that require data exchange or storage. SAMPLE JSON JSON ARRAY JSON Arrays are simple structures that hold simple list of items, just like a Java array or ArrayList JSON Arrays enclosed in square brackets: [ ] Example: [“Apples”,”Banana”,23,true] JSON OBJECT (MAP) JSON Objects are key/value structures that hold a simple list of items, just like a Java array or ArrayList JSON Arrays enclosed in curly braces: {} Example: {“Name”:”Jane”,”Email”:[email protected]} JSON DOCUMENTS JSON documents are structured using a combination of JSON Array and JSON Objects Example: Consider the requirement to store all students in class where each student has a Name, Email Address, and Phone Number as data fields Individual students will be stored in a JSON object All students will be stored in a JSON array Each entry in the JSON array will be a JSON object containing an individual student JSON DOCUMENTS [ {”Name”:”Student1”, “Email”:”[email protected]”, “Phone”:”Student1Phone”}, {”Name”:”Student2”, “Email”:”[email protected]”, “Phone”:”Student2Phone”} ] JSON LIBRARY To work with JSON objects in Java a third-party library will be required A library called Simple JSON can be downloaded from: http://www.java2s.com/Code/Jar/j/Downloadjsonsimple111jar.htm The library consists of a Java Archive File (.jar) called json-simple-1.1.1.jar The library was made by a third party that compiled Java classes and packaged them in a.jar file You will need to add the library to your IDE and the classpath to use it

Use Quizgecko on...
Browser
Browser