http

package
v0.39.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

HTTP adapter

HTTP adapter provides an HTTP API for sending messages and commands through the platform.

Authentication

The Authorization header identifies the Thing making the request. Three formats are supported:

Format Header value Notes
Internal key Authorization: Thing <key> Standard Thing key
External key Authorization: External <key> External/third-party Thing key

Configuration

The service is configured using the environment variables presented in the following table. Note that any unset variables will be replaced with their default values.

Variable Description Default
MF_HTTP_ADAPTER_LOG_LEVEL Log level (debug, info, warn, error) error
MF_HTTP_ADAPTER_PORT Service HTTP port 8180
MF_HTTP_ADAPTER_CLIENT_TLS Flag that indicates if TLS should be turned on for gRPC false
MF_HTTP_ADAPTER_CA_CERTS Path to trusted CAs in PEM format for gRPC TLS
MF_BROKER_URL Message broker instance URL nats://localhost:4222
MF_THINGS_AUTH_GRPC_URL Things service Auth gRPC URL localhost:8183
MF_THINGS_AUTH_GRPC_TIMEOUT Things service Auth gRPC request timeout in seconds 1s
MF_JAEGER_URL Jaeger server URL for distributed tracing. Leave empty to disable tracing.

Deployment

The service itself is distributed as Docker container. Check the http-adapter service section in docker-compose to see how the service is deployed.

To start the service outside of the container, execute the following shell script:

# Download the latest version of the service
git clone https://github.com/MainfluxLabs/mainflux

cd mainflux

# compile the http adapter
make http

# Copy binary to bin
make install

# Set the environment variables and run the service
MF_HTTP_ADAPTER_LOG_LEVEL=[Log level] \
MF_HTTP_ADAPTER_PORT=[Service HTTP port] \
MF_HTTP_ADAPTER_CA_CERTS=[Path to trusted CAs in PEM format] \
MF_BROKER_URL=[Message broker instance URL] \
MF_THINGS_AUTH_GRPC_URL=[Things service Auth gRPC URL] \
MF_THINGS_AUTH_GRPC_TIMEOUT=[Things service Auth gRPC request timeout] \
MF_JAEGER_URL=[Jaeger server URL] \
$GOBIN/mainfluxlabs-http

Usage

For the full API reference, see the API documentation.

Documentation

Overview

Package http contains the domain concept definitions needed to support Mainflux http adapter service functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service interface {
	// Publish Message
	Publish(ctx context.Context, key domain.ThingKey, msg protomfx.Message) error
	// SendCommandToThing publishes a command message to the specified thing.
	SendCommandToThing(ctx context.Context, token, thingID string, msg protomfx.Message) error
	// SendCommandToThingByKey publishes a command message to the specified thing, authorized by publisher thing key (M2M).
	SendCommandToThingByKey(ctx context.Context, key domain.ThingKey, thingID string, msg protomfx.Message) error
	// SendCommandToGroup publishes a command message to things that belong to a specified group, authorized by user token.
	SendCommandToGroup(ctx context.Context, token, groupID string, msg protomfx.Message) error
	// SendCommandToGroupByKey publishes a command message to a group, authorized by publisher thing key (M2M).
	SendCommandToGroupByKey(ctx context.Context, key domain.ThingKey, groupID string, msg protomfx.Message) error
}

Service specifies coap service API.

func New

New instantiates the HTTP adapter implementation.

Directories

Path Synopsis
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL