Back to Examples
- Binding patterns
- Typed binding pattern
- Wildcard binding pattern
- List binding patterns
- Rest binding pattern in list binding pattern
- Mapping binding pattern
- Rest binding pattern in mapping binding pattern
- Error binding pattern
- Rest binding pattern in error binding pattern
- Single use of typed binding patterns
- Single use of typed binding patterns with on fail clause
- Iterative use of typed binding patterns
- List binding pattern in match statement
- Mapping binding pattern in match statement
- Error binding pattern in match statement
- Query expressions
- Sort iterable objects
- Let clause
- Limit clause
- Join iterable objects
- Outer Join clause
- Query tables
- Create tables with a query
- Create maps with a query
- Create streams with a query
- On conflict clause
- Advanced conflict handling
- Iterate over XML with a query
- Nested query expressions
- Destructure records using a query
- Querying streams
- Aggregation
- JSON type
- Access JSON elements
- Access optional JSON elements
- Match statement with maps
- Convert from user-defined type to JSON
- Convert from table and XML to JSON
- Convert from JSON to user-defined type
- Cast JSON to user-defined type
- Resource method typing
- JSON numbers
- JSON to record
- JSON to record with projection
- JSONPath expressions
- Asynchronous function calls
- Named workers
- Sequence diagrams
- Wait for workers
- Strands
- Named worker return values
- Alternate wait
- Multiple wait
- Named workers and futures
- Inter-worker message passing
- Alternate receive
- Multiple receive
- Conditional send
- Inter-worker failure propagation
- Named worker with on fail clause
- Synchronize message passing
- Asynchronize message passing
- Flush
- Fork
GraphQL client - Basic authentication
The graphql:Client
can connect to a service that is secured with basic authentication by adding the Authorization: Basic <token>
header to each request. The username and password for basic authentication can be specified in the auth
field of the graphql:ClientConfiguration
. Use this to communicate with the service, which is secured with basic authentication.
import ballerina/graphql;
import ballerina/io;
// User-defined data types to retrieve data from the service.
type ProfileResponse record {|
*graphql:GenericResponseWithErrors;
record {|Profile profile;|} data;
|};
type Profile record {|
string name;
int age;
|};
public function main() returns error? {
// Defines the GraphQL client to call the APIs secured with basic authentication.
graphql:Client graphqlClient = check new ("localhost:9090/graphql",
auth = {
username: "ldclakmal",
password: "ldclakmal@123"
},
secureSocket = {
cert: "../resource/path/to/public.crt"
}
);
// Defines the GraphQL document to be sent to the GraphQL service.
string document = "{ profile { name, age } }";
// Execute the document and retrieve the response from the GraphQL service.
ProfileResponse response = check graphqlClient->execute(document);
io:println(response.data.profile);
}
Prerequisites
- • Run the GraphQL service given in the Basic authentication file user store example.
Run the client program by executing the following command.
$ bal run graphql_client_security_basic_auth.bal{"name":"Walter White","age":51}
Related links
PreviousMutual SSL
NextSelf-signed JWT authentication