API Model for File Service
Let's understand the API endpoints and data entities required to interact with the API successfully.
Now we know the workflow of the file API and the architecture that best suits our needs. The next step is to identify the data entities involved in the API calls to meet the functional requirements and map those API calls to the chosen architecture (REST).
Base URL and API endpoints
The base URL is the common/shared path of all endpoints of the API service. Below is a structural breakdown of the base URL of our file service:
Basic operations
The figure below shows a summary of the operations and the HTTP verbs used with the various endpoints defined by the file API.
Message format for API endpoints
Let's discuss the data entities and the request-response format involved in our API calls.
File API data entities
Our API will make use of the following data entities while performing different functions.
type file{fileId: string // Unique identifier of a file on the host systemownerId: string // Unique identifier of a user on the host systemauthToken: string // Token verifying the authenticity and privileges of the userchecksum: string // Hash value verifying the integrity of datafileLink: string // The URI of the stored the file contentsuserList: list // A list of users with the specified permissions to access the resourcetimeStamp: date // The data and time at which the particular file is uploadedfileTitle: string // The name/title of the file along with its extensionfileSize: long // Total size of a file in bytescontent: binary // The actual content of a file being transferredmimeType: * // file format or extension of the file such as png, jpeg, mp3, mkv, etc.}
Preconditions
Before discussing the file API model, we assume the following:
Our server is configured to handle file size limits and other similar checks.
The user is logged in.
We provide a flat directory structure for the user to manage files.
Upload a file
Users can upload a file specifying the relevant HTTP method and request format and get a response from the server.
HTTP method: The HTTP
POST
...