关于/type/<type>/id/<id>模式的使用方法及NGSI v2兼容性问询
/type/<type>/id/<id> Pattern Usage & NGSI v2 Support Great question! Let's break this down clearly based on Orion Context Broker's behavior:
1. How to use the /type/<type>/id/<id> URL pattern
This pattern is built for NGSI 9/10 (v1 API) to explicitly target entities with a specific type, fixing the ambiguity that can come with the default empty-type implicit behavior. Here's how to apply it across common operations:
Retrieve an entity's context: Send a
GETrequest to the full path. For example, to fetch aCarentity with IDCar123, the URL would be:GET /v1/contextEntities/type/Car/id/Car123This guarantees you're only accessing the entity of type
Carwith that ID—critical if another entity (like aTruck) shares the same ID.Update an entity's attributes: Use a
POSTrequest to the attributes subpath of the pattern. For instance, to update thespeedattribute of the sameCarentity:POST /v1/contextEntities/type/Car/id/Car123/attributesInclude the updated attribute data in the request body following NGSI v1 format.
Delete an entity: Send a
DELETErequest to the entity path:DELETE /v1/contextEntities/type/Car/id/Car123
In short, this pattern replaces the default empty-type segment in v1's convenience operations with an explicit type value, making your entity targeting precise and unambiguous.
2. Does this pattern support NGSI v2?
No, the /type/<type>/id/<id> pattern is exclusive to NGSI v1 (NGSI9/10). NGSI v2 uses a more streamlined API design where entity uniqueness is defined by the combination of id and type, and it uses a different approach to specify the type:
- To target a specific entity by
idandtypein NGSI v2, use the base entity path with atypequery parameter. For example, retrieving the sameCar123entity:GET /v2/entities/Car123?type=Car - When creating or updating entities in v2, you include the
typedirectly in the request body (as part of the entity JSON structure), rather than embedding it in the URL path.
NGSI v2's design eliminates the need for the v1-style URL pattern by integrating type as a core part of the entity's identity, handled either via query parameters or request body fields.
内容的提问来源于stack exchange,提问作者Júlio Zinga

