Câu hỏi phỏng vấn API Design
Câu hỏi

What are the best practices to create a standard URI for a web service?

Câu trả lời

Creating a standard URI for a web service involves adhering to several best practices to ensure the URI is intuitive, consistent, and maintainable. Here are the key best practices:

General Principles

  1. Use Lowercase Letters: Always use lowercase letters in URIs to avoid case sensitivity issues and ensure consistency[1][4][7].
  2. Use Hyphens for Readability: Separate words in URIs with hyphens rather than underscores or spaces to improve readability[1][4][9].
  3. Avoid Special Characters and File Extensions: Do not use special characters or file extensions in URIs. Use the Content-Type header to specify the format of the response instead[4][9].

Structure and Hierarchy

  1. Use Nouns, Not Verbs: URIs should represent resources (nouns) rather than actions (verbs). The HTTP methods (GET, POST, PUT, DELETE) should indicate the action to be performed[1][7][13].
  2. Hierarchical Structure: Use forward slashes (/) to indicate a hierarchical relationship between resources. This helps in organizing and structuring the URIs logically[8][13].
  3. Avoid Trailing Slashes: Do not include a trailing forward slash at the end of URIs as it adds no semantic value and can cause confusion[4][8][13].

Resource Identification

  1. Plural for Collections, Singular for Single Resources: Use plural nouns for URIs that return a collection of resources and singular nouns for URIs that return a single resource[1][7][13].
  2. Versioning: Include the version number in the URI to manage changes and maintain backward compatibility. This is typically done at the base of the URI (e.g., /v1/)[1][7].

Query Parameters and Filtering

  1. Use Query Parameters for Filtering and Searching: For operations like filtering, sorting, and pagination, use query parameters rather than creating new URIs[1][13][17].

Security and Maintenance

  1. Avoid Exposing Internal Architecture: Do not expose the internal workings of your system in the URI. Keep the URIs clean and abstracted from the underlying implementation[1][4].
  2. **Human-Read...
middle

middle

Gợi ý câu hỏi phỏng vấn

junior

Mention whether you can use GET request instead of PUT to create a resource?

middle

What is Payload?

senior

Which type of Webservices methods are to be idempotent?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào