preface

I’m probably one of the few people who shows interface documentation directly in articles. I’ve been thinking for a long time about whether or not to explain the considerations of product interface development.

Client development and server development are natural enemies and brothers. Hopefully this article will help you fight less and give “love” to each other.

Interface design

The paper

In the design of e-commerce system, the more complex interface is the interface of commodity details, and the response parameters are especially many and complicated. There are several principles to follow when developing an interface to get commodity details

  • Return a small number of JSON nesting
  • You can query the specified SKU
  • Other interface related specifications

Query SKU

As for querying the SKU, HERE’s what I asked my friend to do: First pull out the specifications and attributes

"Colors" : [{" name ":" silver ", "id" : 75}], "choose version" : [{" name ":" open edition ", "id" : 77}, {" name ":" [original extended warranty version] ", "id" : 78}], "memory" : [ { "name": "64G", "id": 82 }, { "name": "256G", "id": 83 } ],Copy the code

Yeah, you read that right, it’s actually the specification as the key, the property as the value. After value[id] is extracted and spliced, the corresponding SKU can be queried.

Response parameter [Specification name][Attribute code] = necessary to splice SKU stringsCopy the code

Specifications are a grouping, and attributes are an important part of a splicing SKU. Take the above data as an example

75_77_82 = Silver, public, 64GBCopy the code

Interface documentation

Request the address

/v1/product/{productId}

Request type

GET

Request parameters

parameter type The default value instructions
productId int 0 Commodity code

In response to the sample

{"id": 131, "name": "Apple iPhone X (A1865) 64GB Deep Space Gray Mobile China Unicom 4G mobile phone ", "price": "8388.00", "market_price": "8388.00", "Sketch ": "IPhone great, 10% off, 10% off, quick chop hands ", "intro": "This is commodity description", "keywords" : [' apple ', 'the iphone], "attribute" : {" colors ": [{" name" : "silver", "id" : 75}, {" name ":" deep gray, "" id" : 76}], "choose version" : [{" name ":" open edition ", "id" : 77}, {" name ":" [original extended warranty version] ", "id" : 78}, {" name ":" double netcom edition ", "id" : 79}, {" name ": "Wireless charging kit", "id" : 80}, {" name ":" Airpods suit ", "id" : 81}], "memory" : [{" name ":" 64 g ", "id" : 82}, {" name ":" 256 g ", "id" : 83}], "purchases" : [{" name ":" official standard ", "id" : 84}, {" name ":" mobile preferential purchase ", "id" : 85}, {" name ":" telecom preferential purchase ", "id" : 86}, {" name ": "Unicom preferential purchase", "id" : 87}}, "album" : [{" id ": 2," name ":" this is the first picture ", "url" : "Http://xxx.com/59ec33eaN6ddb0c54.jpg"}, {" id ": 3," name ":" this is the second image ", "url" : "Http://xxx.com/59ec3400Nce4cc116.jpg"}], "radio" : {" id ": 1," name ":" this is a video ", "url" : "Http://xxx.com/1.mp4"}, "sku" : {" 75 _77_82_84 ": {" id" : 1018, "name" : "choose color: silver; Select version: Public version; Memory: 64 g; Purchase method: Official standard; , "price" : "8388.00", "stock" : 83888388}, "75 _77_82_85" : {" id ": 1019," name ":" choose color: silver; Select version: Public version; Memory: 64 g; How to buy: Mobile Discount;" , "price" : "8388.00", "stock" : 83888388}, "75 _77_82_86" : {" id ": 1020," name ":" choose color: silver; Select version: Public version; Memory: 64 g; How to buy: Telecom Discount;" , "price" : "8388.00", "stock" : 83888388}, "75 _77_82_87" : {" id ": 1021," name ":" choose color: silver; Select version: Public version; Memory: 64 g; Purchase method: Unicom preferential purchase; , "price" : "8388.00", "stock" : 83888388}, "75 _77_83_84" : {" id ": 1022," name ":" choose color: silver; Select version: Public version; Memory: 256 g; Purchase method: Official standard; , "price" : "8388.00", "stock" : 83888388}, "75 _77_83_85" : {" id ": 1023," name ":" choose color: silver; Select version: Public version; Memory: 256 g; How to buy: Mobile Discount;" , "price": "8388.00", "stock": 83888388}}}}Copy the code

Response Parameter Description

Core parameter

parameter type The default value instructions
id int 0 Commodity code
name string Commodity title
price double 00.00 Commodity prices
keywords string Commodity keywords
market_price double 00.00 The market price
virtual int 0 Virtual sales
sketch string Commodity description
intro string Goods details

Commodity chart parameters

parameter type The default value instructions
album[] array [] Commodity rotation chart
id int 0 Resource coding
name string Image name
url string Resource path

Commodity video parameters

If there is no video, return []

parameter type The default value instructions
radio[] array [] Commodity video
id int 0 Resource coding
name string The name of the video
url string Resource path

Commodity specifications/attribute parameters

parameter type The default value instructions
attribute array[] [] Commodity attribute
[(attr_name)] [] array[] [] The attribute name
name string Attribute item name
id int 0 Attribute item encoding

Commodity SKU parameters

parameter type The default value instructions
sku[] array[] [] Goods sku
[(option_id)] [] array[] The SKU of a commodity can be queried using attribute[(attr_name)][‘ ID ‘] splicing
id int 0 Sku coding
name string The name of the sku
price double 00.00 Commodity prices
stock int 0 inventory

Thank you

Thank you for reading this. I hope this article can help you. If you have any questions, please feel free to discuss them in the comments section.

communication

There is life, there is code.

Spread the positive energy of technology and continue to learn new knowledge.