qiandrew / AudioNote

Apache License 2.0
0 stars 0 forks source link

Basic Requests Working #14

Closed matthewmoss closed 5 years ago

matthewmoss commented 5 years ago

Closes #2, #23,

Overview

We use Spring to create a REST API that lets us run our code from anywhere just by calling a URL.

Here's a breakdown of how the backend is used:

  1. The client can call a specific url to perform a specific action.
  2. The URL request triggers our code to run.
  3. Our code returns a response to the client.
  4. The client displays the response.

Ex: To transcribe an audio file, you would send a request to the URL "test.com/transcribe" and receive the transcription in response.

This is basically what's happening whenever you use a website. Ex: To view a profile on Twitter, you enter the url "twitter.com/jack" and it will show the profile with username "jack". The URL triggers some code, which returns the profile in the form of HTML, which the browser displays to you.

The only difference with our use case is that we send responses in JSON instead of HTML. JSON is a super simple way of organizing information and is the industry standard.

How it works rn

  1. Clone the repo to your desktop from Github.
  2. Navigate to the "Backend" directory in the command line.
  3. Run mvn spring-boot:run. This will start the server.
  4. Open localhost:8080 to see our home page.
  5. Type localhost:8080/transcription?audio=test to receive a basic response from the API.

What is a REST API

A REST API is a set of conventions about how you use a URL to perform an action.

When you send a request to a REST API, you tell it the URL, the type of action you want to perform, and any parameters needed to perform the action.

REST supports a few different types of actions, known as methods:

POST - Used when you are creating a new object. Ex: Create a new user in your database. PUT - Update an existing object. Ex: Change a user's name. GET - Fetch a single existing object. Ex: Given an ID, get the info on the user. INDEX - Fetch a group of existing objects. Ex: Get all users. DELETE - Delete an existing object.

To perform a specific action, you need to include both the method and url in your request. Ex: the url "/users/1" can have many methods associated with it. Send a GET request to this url and you get back the user, send a PUT to edit the user, send a DELETE too delete the user.

matthewmoss commented 5 years ago

Also, here's the tutorial I used if anyone's interested: https://spring.io/guides/gs/rest-service/#scratch