Services
The integration enables QA and development teams to perform API-level testing using Cypress with the added capabilities of the Ordino Engine. Key benefits:
Direct access to Ordino Engine features within Cypress test suites.
Flexible service class design for encapsulating business rules.
Built-in TypeScript/JavaScript support.
Prerequisites
Before you begin, ensure the following dependencies and requirements are met:
Node.js
>= 22.x
Cypress
>= 13.x
Package Manager
npm
or yarn
Language Support
TypeScript / JavaScript
Installation
Add @ordino.ai/ordino-engine
to your Cypress project:
npm install @ordino.ai/ordino-engine@2.2.0-cy.8 --save-dev
A recommended directory layout for using @ordino.ai/ordino-engine
with Cypress:
/ordino
/e2e
/api
users.spec.ts
/services
add_user.ts
/payloads
user_info.ts
/support
commands.ts
cypress.config.ts
package.json
Directory / File Details
/e2e/api/
Contains your end-to-end test specifications.users.spec.ts
→ Example Cypress spec file testing user-related API endpoints.
/services/
Houses service classes that encapsulate API calls and business logic.add_user.ts
→ Example service class for handling user-related API operations.
/payloads/
Stores request/response payloads used in tests.user_info.ts
→ Example test payload for creating or validating users data.
/support/
Contains Cypress custom commands and global hooks.commands.ts
→ Extend Cypress with reusable commands for common actions.
cypress.config.ts
Cypress configuration file. Define base URL, environment variables, and test settings here.package.json
Project dependencies, scripts, and metadata. Includes the installed@ordino.ai/ordino-engine
package.
Engine Import
In any service or test file, import the HTTP API from @ordino.ai/ordino-engine
:
import { ordinoSuite } from '@ordino.ai/ordino-engine';
const http = ordinoSuite.api(ApiServiceType.HTTP);
ordinoSuite
→ Main entry point to the Ordino Engine.ApiServiceType.HTTP
→ Specifies that the API service should use HTTP as the communication layer.http
→ An initialized API client instance to perform requests.
Core HTTP Methods
Ordino provides a rich set of HTTP helper methods for building and executing API requests:
Method
Description
BaseUrl(url: string)
Set the base API URL.
setUrl(path: string)
Set the endpoint path.
setHeaders(obj)
Set request headers (local to request).
clearHeaders()
Clear locally set headers.
setGlobalHeader(key, value)
Set a header for all requests.
clearGlobalHeaders()
Remove all globally set headers.
setValue(key, value)
Store a variable in memory.
getValue(key)
Retrieve a stored variable.
requestGet()
Send a GET request.
requestPost(data)
Send a POST request with body data.
requestPut(data)
Send a PUT request with body data.
requestDelete()
Send a DELETE request.
requestGetWithQuery(query)
Send a GET request with query params.
Writing API Requests
GET Request
Example of sending a GET request with Ordino Engine in Cypress:
http.BaseUrl("https://api.example.com");
http.setUrl('/users/123');
http.requestGet().then((response) => {
expect(response.status).to.eq(200);
expect(response.body.id).to.eq('123');
});
BaseUrl()
→ Defines the API base URL.setUrl()
→ Sets the endpoint path.requestGet()
→ Executes a GET request.
POST Request
Example of sending a POST request with headers and payload:
http.BaseUrl("https://api.example.com");
http.setUrl('/users');
http.setHeaders({
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
});
http.requestPost({ name: 'John Doe', email: 'john@example.com' })
.then((response) => {
expect(response.status).to.eq(201);
http.setValue("userId", response.body.id); // store for later use
});
setHeaders()
→ Adds request-specific headers.requestPost(data)
→ Sends a POST request with the given payload.setValue(key, value)
→ Stores values (e.g., IDs, tokens) for later requests.
PUT Request
Example of updating a resource using PUT:
const userId = http.getValue("userId");
http.BaseUrl("https://api.example.com");
http.setUrl(`/users/${userId}`);
http.setHeaders({
'Content-Type': 'application/json'
});
http.requestPut({ name: 'John Updated' })
.then((response) => {
expect(response.status).to.eq(200);
});
getValue()
→ Retrieves a stored variable (e.g.,userId
from a previous request).requestPut(data)
→ Sends a PUT request with the specified payload.
DELETE Request
Example of deleting a resource using DELETE:
const userId = http.getValue("userId");
http.BaseUrl("https://api.example.com");
http.setUrl(`/users/${userId}`);
http.requestDelete()
.then((response) => {
expect(response.status).to.eq(204);
});
requestDelete()
→ Executes a DELETE request.Commonly used to clean up test data after execution.
Last updated