======================================
This tutorial shows how to use a locally installed version of Golang to interact with the EVSREST API. Shown here are examples that demonstrate the range of functionality that the EVSREST API has. Many of these API calls can take in different parameters than the ones shown.
- Golang 1.18 or higher must be installed. The latest version can be found here.
Install the following dependencies via command line in the go-examples
directory:
go get github.com/stretchr/testify/assert
go get github.com/stretchr/testify/require
go get golang.org/x/net/context
Each operation can use different server URL defined using url
in configuration.go. This file includes a list of currently supported API environments. To change the environment used to run, set the url variable to the desired environment mentioned in the url mapping baseUrls
// Define base URLs for different environments
baseUrls := map[string]string{
"development": "https://api-evsrest-dev.nci.nih.gov/",
"testing": "https://api-evsrest-test.nci.nih.gov/m",
"production": "https://api-evsrest.nci.nih.gov/",
"local": "http://localhost:8082",
}
// define environment
url := baseUrls["production"] // set API environment here
cfg := &Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Servers: ServerConfigurations{
{
URL: url, // configuration built based on selected baseUrl
Description: "No description provided",
},
},
OperationServers: map[string]ServerConfigurations{},
}
To run a specific test from a test file, use the -run
flag with the name of the test:
go test -run "^TestMetadataEndpointsAPIService/GetAssociationByCode$" api_metadata_endpoints_test.go
The "^$" surrounding test name is necessary to run only the specified test, as go defaults to running all substring matches of the run parameter.
You can run multiple tests that match a regular expression:
go test -run 'TestMetadataEndpointsAPIService/GetAssociationByCode|GetAssociations' api_metadata_endpoints_test.go
To execute all tests in a specific test file:
go test api_metadata_endpoints_test.go
To run all tests in all files across the entire directory:
go test ./...
To see detailed output of each test, including pass/fail status and log output, add the -v flag:
go test -v api_metadata_endpoints_test.go # For a single file
go test -v ./... # For all tests in the project
The -v verbose option is necessary to see the exact output of each API call made in the tests. They will otherwise only display success or failure states.
The following examples are exhibited by various unit tests defined in the code in go-examples
.
All commands to run these tests should be run from that directory.
- Get terminologies
- Get concept by code (minimal information)
- Get concepts by list (minimal information)
- Get concept by code (summary information)
- Get concept by code (full information)
- Get concept by code (custom include)
- Get concept part
- Get concept descendants
- Get all properties
- Get property by code (or label)
- Get all qualifiers
- Get qualifier by code (or label)
- Get qualifier values by code (or label)
- Get all roles
- Get role by code (or label)
- Get all associations
- Get association by code (or label)
- Get all term types
- Get all synonym sources
- Get all definition types
- Get definition type by code
- Get all synonym types
- Get synonym type by code
- Find root concepts
- Get paths to/from root from a code
- Get paths to an ancestor code from a code
- Get subtree for code
- Find concepts by search term (use paging to get only first 5 results)
- Find concepts by search term (restrict by concept status)
- Find concepts by search term (restrict by definition source)
- Find concepts by search term (restrict by definition type)
- Find concepts by search term (restrict by synonym source and termgroup)
- Find concepts by search term (restrict by synonym type)
- Find concepts by search term (where search term is a code)
- Find concepts by search term (using type=match)
- Find concepts by search term (using type=startsWith)
- Find concepts by search term (using type=phrase)
- Find concepts by search term (using type=fuzzy)
- Find concepts by search term (using type=AND)
- Find concepts by search term (using type=OR)
- Find concepts by search term (with highlights)
- Find concepts by property
- Find concepts by subset
- Find concepts by SPARQL code
- Get all subsets
- Get subset by code
- Get subset members by subset code
- Get all mapsets
- Get mapset by code
- Get maps by mapset code
- Get replacement concepts for an inactive concept code
- Get replacement concepts for a list of inactive concept codes
- Get SPARQL bindings from query
Return all loaded terminologies currently hosted by the API.
go test -run "^TestMetadataEndpointsAPIService/GetTerminologies$" api_metadata_endpoints_test.go -v
Return concept object with minimal information for a specified code.
go test -run "^TestConceptEndpointsAPIService/GetConcept$" api_concept_endpoints_test.go -v
Return concept objects with minimal information for a specified list of codes.
go test -run "^TestConceptEndpointsAPIService/GetConcepts$" api_concept_endpoints_test.go -v
Return concept object with summary information for a specified code.
go test -run "^TestConceptEndpointsAPIService/GetConceptSummary$" api_concept_endpoints_test.go -v
Return concept object with full information for a specified code.
go test -run "^TestConceptEndpointsAPIService/GetConceptFull$" api_concept_endpoints_test.go -v
Return custom concept information for a given terminology and code. To show a range of options, in this case, the request asks for synonyms, children, maps, and inverse associations.
go test -run "^TestConceptEndpointsAPIService/GetConceptCustomInclude$" api_concept_endpoints_test.go -v
Returns sub-part of the concept for a given terminology and code. NOTE: in the call below, you can replace "children" in the URL with any of the following and retrieve the corresponding underlying info: children, parents, roles, associations, inverseRoles, inverseAssociations, maps.
go test -run "^TestConceptEndpointsAPIService/GetChildren$" api_concept_endpoints_test.go -v
Return concept descendants information for a given terminology and code. The call client can be constrained by a maxLevel to prevent going deeper than a certain amount. Level 0 entries in the result are the direct children. The test sets the max level to 2.
go test -run "^TestConceptEndpointsAPIService/GetDescendants$" api_concept_endpoints_test.go -v
Return all properties for a given terminology with default include setting (minimal).
go test -run "^TestMetadataEndpointsAPIService/GetProperties$" api_metadata_endpoints_test.go -v
Return property for the specified code or label.
go test -run "^TestMetadataEndpointsAPIService/GetProperty$" api_metadata_endpoints_test.go -v
Return all qualifiers for a given terminology with default include setting (minimal).
go test -run "^TestMetadataEndpointsAPIService/GetQualifiers$" api_metadata_endpoints_test.go -v
Return qualifier for the specified code or label.
go test -run "^TestMetadataEndpointsAPIService/GetQualifier$" api_metadata_endpoints_test.go -v
Return distinct value set for the qualifier with the specified code or label.
go test -run "^TestMetadataEndpointsAPIService/GetQualifierValues$" api_metadata_endpoints_test.go -v
Return all roles.
go test -run "^TestMetadataEndpointsAPIService/GetRoles$" api_metadata_endpoints_test.go -v
Returns a role definition for a specified code.
go test -run "^TestMetadataEndpointsAPIService/GetRole$" api_metadata_endpoints_test.go -v
Return all associations.
go test -run "^TestMetadataEndpointsAPIService/GetAssociations$" api_metadata_endpoints_test.go -v
Returns associations for a specified code.
go test -run "^TestMetadataEndpointsAPIService/GetAssociationByCode$" api_metadata_endpoints_test.go -v
Return metadata for all term types for the specified terminology.
go test -run "^TestMetadataEndpointsAPIService/GetTermTypes$" api_metadata_endpoints_test.go -v
Return metadata for all synonym sources for the specified terminology.
go test -run "^TestMetadataEndpointsAPIService/GetSynonymSources$" api_metadata_endpoints_test.go -v
Return metadata for all definition sources for the specified terminology.
go test -run "^TestMetadataEndpointsAPIService/GetDefinitionSources$" api_metadata_endpoints_test.go -v
Return metadata for all definition types for the specified terminology.
go test -run "^TestMetadataEndpointsAPIService/GetDefinitionTypes$" api_metadata_endpoints_test.go -v
Get definition type by code. Include parameter allowed customizing how much data to return.
go test -run "^TestMetadataEndpointsAPIService/GetDefinitionTypeByCode$" api_metadata_endpoints_test.go -v
Return metadata for all synonym types for the specified terminology.
go test -run "^TestMetadataEndpointsAPIService/GetSynonymTypes$" api_metadata_endpoints_test.go -v
Return metadata for all synonym types for the specified terminology.
go test -run "^TestMetadataEndpointsAPIService/GetSynonymTypeByCode$" api_metadata_endpoints_test.go -v
Return all root concepts for the specified terminology.
go test -run "^TestConceptEndpointsAPIService/GetRoots$" api_concept_endpoints_test.go -v
Return paths to/from the root concept from a specified terminology and code.
go test -run "^TestConceptEndpointsAPIService/GetPathsFromRoot$" api_concept_endpoints_test.go -v
go test -run "^TestConceptEndpointsAPIService/GetPathsToRoot$" api_concept_endpoints_test.go -v
Return paths to the root concept for a specified terminology and code.
go test -run "^TestConceptEndpointsAPIService/GetPathsToAncestor$" api_concept_endpoints_test.go -v
Return an entire subtree graph from the root concepts to a specified node. This call is specifically tuned to support a tree-view based hierarchy browser in a UI.
go test -run "^TestConceptEndpointsAPIService/GetSubtree$" api_concept_endpoints_test.go -v
Find concepts matching a search term within a specified terminology. This example uses paging to get only the first 5 results. Include is set to minimal.
go test -run "^TestSearchEndpointAPIService/GetSearch$" api_search_endpoint_test.go -v
Find concepts matching a search term within a specified terminology and restrict the search results by concept status of "Retired_Concept". This example uses paging to get only the first 5 results.
go test -run "^TestSearchEndpointAPIService/GetSearchFilterByConceptStatus$" api_search_endpoint_test.go -v
Get concepts matching a search term within a specified terminology and restrict the search results by a definition source of "NCI". This example uses paging to get only the first 5 results.
go test -run "^TestSearchEndpointAPIService/GetSearchFilterByDefinitionSource$" api_search_endpoint_test.go -v
Find concepts matching a search term within a specified terminology and restrict the search results by a definition type of "DEFINITION". This example uses paging to get only the first 5 results.
go test -run "^TestSearchEndpointAPIService/GetSearchFilterByDefinitionType$" api_search_endpoint_test.go -v
Find concepts matching a search term within a specified terminology and restrict the search results by a synonym source of "NCI" and synonymTermGroup of "PT".
go test -run "^TestSearchEndpointAPIService/GetSearchFilterBySynonymSourceAndTermType$" api_search_endpoint_test.go -v
Find concepts matching a search term within a specified terminology and restrict the search results by a synonym type of "FULL_SYN".
go test -run "^TestSearchEndpointAPIService/GetSearchFilterBySynonymType$" api_search_endpoint_test.go -v
go test -run "^TestSearchEndpointAPIService/GetSearchByCode$" api_search_endpoint_test.go -v
Find concepts matching a search term within a specified terminology and a search type of "match". This example uses paging to get only the first 5 results.
go test -run "^TestSearchEndpointAPIService/GetSearchByTypeMatch$" api_search_endpoint_test.go -v
Find concepts matching a search term within a specified terminology and a search type of "startsWith".This example uses paging to get only the first 5 results.
go test -run "^TestSearchEndpointAPIService/GetSearchByTypeStartsWith$" api_search_endpoint_test.go -v
Find concepts matching a search term within a specified terminology and a search type of "phrase". This example uses paging to get only the first 5 results.
go test -run "^TestSearchEndpointAPIService/GetSearchByTypePhrase$" api_search_endpoint_test.go -v
Find concepts matching a search term within a specified terminology and a search type of "fuzzy". This example uses paging to get only the first 5 results.
go test -run "^TestSearchEndpointAPIService/GetSearchByTypeFuzzy$" api_search_endpoint_test.go -v
Find concepts matching a search term within a specified terminology and a search type of "and". This example uses paging to get only the first 5 results.
go test -run "^TestSearchEndpointAPIService/GetSearchByTypeAnd$" api_search_endpoint_test.go -v
Find concepts matching a search term within a specified terminology and a search type of "or". This example uses paging to get only the first 5 results.
go test -run "^TestSearchEndpointAPIService/GetSearchByTypeOr$" api_search_endpoint_test.go -v
Find concepts matching a search term within a specified terminology and include synonyms and highlighted text in the response. This example uses paging to get only the first 5 results.
go test -run "^TestSearchEndpointAPIService/GetSearchWithHighlights$" api_search_endpoint_test.go -v
Find concepts matching a search term that is searched within a certain set of properties. The search results are set to include the property values, so you can easily see the match. The property setting here can be either based on code or on label
go test -run "^TestSearchEndpointAPIService/GetSearchConceptsByProperty$" api_search_endpoint_test.go -v
Get concepts matching a search term within a specified terminology and subset. This example searches within C165258 (e.g. Cellosaurus Disease Terminology).
go test -run "^TestSearchEndpointAPIService/GetSearchConceptsBySubset$" api_search_endpoint_test.go -v
Find concepts for a specified SPARQL query that returns a ?code field.
go test -run "^TestSearchEndpointAPIService/GetConceptsBySPARQLCode$" api_search_endpoint_test.go -v
Get all subsets for a specified terminology.
go test -run "^TestMetadataEndpointsAPIService/GetSubsets$" api_metadatas_endpoint_test.go -v
Get subset for a specified terminology and code.
go test -run "^TestMetadataEndpointsAPIService/GetSubset1$" api_metadatas_endpoint_test.go -v
Get subset members for a specified terminology and code.
go test -run "^TestMetadataEndpointsAPIService/GetSubsetMembers1$" api_metadatas_endpoint_test.go -v
Get all mapsets. Include parameter allows customizing how much data to return.
go test -run "^TestMapsetEndpointsAPIService/GetMapsets$" api_mapset_endpoints_test.go -v
Get mapset information for a specified code. Include parameter allows customizing how much data to return.
go test -run "^TestMapsetEndpointsAPIService/GetMapsetByCode$" api_mapset_endpoints_test.go -v
Get the maps for a specified mapset code.
go test -run "^TestMapsetEndpointsAPIService/GetMapsetMappingsByCode$" api_mapset_endpoints_test.go -v
Get the replacement concepts for a specified inactive concept code.
go test -run "^TestHistoryEndpointsAPIService/GetReplacements$" api_history_endpoints_test.go -v
Get the replacement concepts for a specified list of inactive concept codes.
go test -run "^TestHistoryEndpointsAPIService/GetReplacementsFromList$" api_history_endpoints_test.go -v
Get SPARQL bindings for a specified SPARQL query.
go test -run "^TestSearchEndpointAPIService/GetSPARQLBindings$" api_search_endpoint_test.go -v