web api

本文由用户“爱可林1”分享发布 更新时间:2022-07-23 01:00:41 举报文档

以下为《web api》的无排版文字预览,完整格式请下载

下载前请仔细阅读文字预览以及下方图片预览。图片预览是什么样的,下载的文档就是什么样的。

PI Web API Reference

PI Web API Help

The PI Web API is a RESTful interface to the PI system. It gives client applications read and write access to their AF and PI data over HTTPS. Use the links on the left to learn about the PI Web API in more detail:

The?Getting Started?section introduces the concepts of a RESTful service in the context of the PI Web API and describes some important general constructs and principles found throughout the API. It concludes with a tutorial demonstrating a simple HTML/CSS/JavaScript client that uses the PI Web API.

The?Controllers?section lists the top-level endpoints provided by the service. Each controller's detail page provides links to the methods exposed by the controller. Use these pages as a reference when programming client applications.

The?Topics?section provides links to detailed specifications of options and features that appear throughout the PI Web API. For example, several methods use time strings for input, output, and query filtering. The Time Strings topic describes the use and formatting of these strings.

The?Changelog?describes the incremental changes included in each release of the PI Web API.

Getting Started with the PI Web API

The PI Web API is a RESTful interface to the PI system. It gives client applications read and write access to their AF and PI data over HTTPS. This getting started guide starts with an overview of the constructs and principles that you'll encounter as you use the API, moves on to examples in the form of sample requests and a simple demo application, and concludes with a discussion of some more specific topics that may enrich your understanding of the API.

REST Principles

REST stands for 'representational state transfer.' In the context of the PI Web API, this means that the API is:

Stateless

The PI Web API is stateless. This means that the service retains no observable knowledge of clients across requests. Each request is an independent transaction between the client and the server. One important consequence of this property is that the check out - make changes - check in transaction pattern found in many database-related APIs (e.g. the AFSDK) is not exposed by the PI Web API. Rather, each request encapsulates this pattern internally.

Resource-oriented

Interaction with the PI Web API is organized around resources. A resource is a structured piece of data that represents an object in one of the PI Systems connected to the Web API. Most important PI and AF objects, such as Asset Servers, Data Servers, points, elements, attributes, event frames, and so on, map to resources in the PI Web API. Four primary operations are used to interact with these resources: create, read, update, and delete (often abbreviated as CRUD).

Navigable by links

Links (also called hypermedia) capture the organization of the resources exposed by the Web API. You're probably familiar with the hierarchical(等级制的; 按等级划分的; 等级制度的) structure of AF objects: Asset Servers contain databases, which contain elements, which contain attributes, and so on. Links express these relationships. For example, an Asset Server resource links to the collection of databases it contains, and each database links to its parent Asset Server.

WebID

Resources that support CRUD operations are the primary objects in the PI Web API. To allow clients to address these resources, the PI Web API must identify them in a way that is both persistent (so that clients can address known resources consistently(一贯地; 始终如一地) over time) and URL-safe (since resources are specified by URLs). Every primary resource in the PI Web API is associated with a WebID, which is an identifier that meets these criteria. Client applications should treat WebIDs as opaque(不透明的; 不透光的) identifiers. Because they are persistent, clients may cache URLs containing WebIDs.

HATEOAS

As discussed above, the resources exposed by the PI Web API are connected by links. This means that client applications should rarely need to construct resource URLs. Rather, they should use Hypermedia as the Engine of Application State (HATEOAS). There are several entry points to the application, including the root of the API and the various GetByPath methods. Once 'inside' the system, the client application should access related resources via the links.

HTTP Verbs

Every resource exposed by the PI Web API supports some subset of the CRUD operations discussed above. Create corresponds to POST, read to GET, update to PUT (when the method requires the complete resource definition) or PATCH (when the method accepts a partial resource definition), and delete to DELETE.

URL Parameters

Several PI Web API GET methods accept URL query parameters. In general, these specify options or serve as filters on the response. For example, element search (GET assetdatabase/{webId}/elements) takes various parameters that specify which elements to return and how to order the returned elements.

JSON

JavaScript Object Notation (JSON) is the primary media type supported by the PI Web API. You can get a feel for JSON by examining the samples provided in the documentation and exploring the API in your browser. Most common client application languages and frameworks provide libraries to convert between language/framework primitives(原始) and JSON strings.

Status Codes

HTTP status codes provide information about the success or failure of a request. The PI Web API adheres to the standard semantics of these codes as closely as possible. A coarse distinction is that 200-level status codes indicate success, 400-level status codes indicate user error, and 500-level status codes indicate server error. 400- and 500-level codes are generally accompanied by a response body providing a friendly error message to assist with debugging. One special case worth noting is that the 201 status code is returned in response to a POST, when a resource has been created. In this case, the response will contain a Location header with the WebID-based URL, which the client may use to access the newly-created resource.

The Structure of a PI Web API Request

In this section, we'll look at a GET request to the PI Web API. Client applications will generally use libraries to take care of the details of constructing HTTP requests, but an understanding of the information contained in a request, coupled with a request inspector like Fiddler, is useful for debugging. The following is a complete GET request to the API:

GET https://myserver/piwebapi/assetdatabases/D0NxzXSxtlKkGzAhZfHOB-KAQLhZ5wrU-UyRDQnzB_zGVAUEhMQUZTMDRcTlVHUkVFTg HTTP/1.1

Host: myserver

Accept: application/json

The first line specifies the GET method, the resource URL, and the protocol version. The next two lines are request headers. The second line specifies the host addressed by the client, and the third line specifies that the client expects to receive a response formatted as JSON. The response looks like this:

HTTP/1.1 200 OK

Content-Length: 1783

Content-Type: application/json; charset=utf-8

Server: Microsoft-HTTPAPI/2.0

Date: Wed, 01 Oct 2014 14:24:13 GMT

{

"WebId": "D0NxzXSxtlKkGzAhZfHOB-KAQLhZ5wrU-UyRDQnzB_zGVAUEhMQUZTMDRcTlVHUkVFTg",

"Id": "e759b840-d40a-4cf9-910d-09f307fcc654",

"Name": "NuGreen",

"Description": "PI BI Project Asset Model",

"Path": "\\\\MyAFServer\\NuGreen",

"Links": {

"Self": "https://myserver/piwebapi/assetdatabases/D0NxzXSxtlKkGzAhZfHOB-KAQLhZ5wrU-UyRDQnzB_zGVAUEhMQUZTMDRcTlVHUkVFTg",

"Elements":"https://myserver/piwebapi/assetdatabases/D0NxzXSxtlKkGzAhZfHOB-KAQLhZ5wrU-UyRDQnzB_zGVAUEhMQUZTMDRcTlVHUkVFTg/elements",

"ElementTemplates":"https://myserver/piwebapi/assetdatabases/D0NxzXSxtlKkGzAhZfHOB-KAQLhZ5wrU-UyRDQnzB_zGVAUEhMQUZTMDRcTlVHUkVFTg/elementtemplates",

"EventFrames":"https://myserver/piwebapi/assetdatabases/D0NxzXSxtlKkGzAhZfHOB-KAQLhZ5wrU-UyRDQnzB_zGVAUEhMQUZTMDRcTlVHUkVFTg/eventframes",

"AssetServer":"https://myserver/piwebapi/assetservers/S0NxzXSxtlKkGzAhZfHOB-KAUEhMQUZTMDQ",

"ElementCategories":"https://myserver/piweba 内容过长,仅展示头部和尾部部分文字预览,全文请查看图片预览。 cts, including tutorials, forums, and sample code. Many samples and tutorials hosted on PI Developers Club assume the presence of the?NuGreen?database, which you can run yourself by importing the?NuGreen XML?into your PI Asset Server.

The PI Web API Users Guide, hosted in?OSIsoft Documentation, contains detailed information on how to run and administer the product. OSIsoft Documentation also contains information on how to install, configure, maintain, and use other components in the PI System.

[文章尾部最后500字内容到此结束,中间部分内容请查看底下的图片预览]

以上为《web api》的无排版文字预览,完整格式请下载

下载前请仔细阅读上面文字预览以及下方图片预览。图片预览是什么样的,下载的文档就是什么样的。

图片预览