TAILIEUCHUNG - Tạo mạng xã hội với PHP - part 38

Developing an API Let's go with REST REST is now a very popular API architecture, with most social networks providing REST-based APIs. The way RESTful APIs rely on descriptive URIs for providing access to data makes them very easy for consumers to utilize, as the URIs provide information on what the request does, and what data it will return. Some implementations, such as the Twitter API even make it possible to change the format of the data returned, simply by changing a part of the URI. Requests Requests to a RESTful API use HTTP verbs to describe what the consumer is trying to do | Developing an API Let s go with REST REST is now a very popular API architecture with most social networks providing REST-based APIs. The way RESTful APIs rely on descriptive URIs for providing access to data makes them very easy for consumers to utilize as the URIs provide information on what the request does and what data it will return. Some implementations such as the Twitter API even make it possible to change the format of the data returned simply by changing a part of the URI. Requests Requests to a RESTful API use HTTP verbs to describe what the consumer is trying to do. The API requests are made to specific URIs which define the resource that the consumer is trying to perform the action determined by the verbs upon. HTTP verbs The HTTP verbs and their usage are described as follows Verb Description GET Retrieve information POST Create records PUT Update records DELETE Delete records Resources RESTful APIs relate URIs to resources. Below are some examples http profiles To list or create profiles http profiles 1 A specific user s profile Our RESTful API will be based within an API controller thus prefixing all URLs with api which goes slightly against the REST concept of a resource. 352 Download from Chapter 11 Resources and verbs the requests Let s look at how resources and verbs combined result in API requests. API operation HTTP verb Creating a user POST Listing users GET Viewing a user s profile GET Updating a profile PUT Deleting a profile DELETE Resource http api profiles http api profiles http api profiles 1 http api profiles 1 http api profiles 1 In the above resources the number 1 represents the ID of a user s profile. Responses The response to an API request is generally made up of two parts. The first part of the response is the HTTP header containing an appropriate status code. Some examples of HTTP status codes are below HTTP status

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.