Skip to content

add new Rest api wrapper - #13965

Merged
Nir-Az merged 3 commits into
realsenseai:developmentfrom
ArthurRaizIntel:rest_api
Jul 2, 2025
Merged

add new Rest api wrapper#13965
Nir-Az merged 3 commits into
realsenseai:developmentfrom
ArthurRaizIntel:rest_api

Conversation

@ArthurRaizIntel

@ArthurRaizIntel ArthurRaizIntel commented Apr 28, 2025

Copy link
Copy Markdown
Contributor

image
Tracked on [LRS-1272]

@Nir-Az
Nir-Az requested a review from Copilot April 28, 2025 08:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new REST API wrapper for interacting with RealSense devices and WebRTC streaming by introducing various endpoints and supporting code.

  • Adds core security functions and placeholder implementations for token creation and password hashing.
  • Introduces several API endpoints for devices, sensors, streams, point cloud, options, and WebRTC communications.
  • Provides dependency injection for service managers and updates documentation to include the new REST API wrapper.

Reviewed Changes

Copilot reviewed 38 out of 39 changed files in this pull request and generated no comments.

Show a summary per file
File Description
app/core/security.py Introduces token creation and password verification placeholders
app/core/errors.py Adds custom error handlers for various FastAPI exceptions
app/core/config.py Provides settings retrieval with an lru_cache decorator
app/core/auth.py Implements basic authentication logic with a fake user database
app/api/router.py Configures API routing to include various endpoint modules
app/api/endpoints/* Implements endpoints for webrtc, streams, sensors, point cloud, options, and devices
app/api/dependencies.py Supplies singleton dependencies for RealSense and WebRTC managers
wrappers/rest-api/README.md & wrappers/readme.md Updates documentation to document the new REST API capabilities
Files not reviewed (1)
  • wrappers/rest-api/.gitignore: Language not supported
Comments suppressed due to low confidence (1)

wrappers/rest-api/app/api/endpoints/point_cloud.py:32

  • Consider renaming 'get_stream_status' to 'get_point_cloud_status' for consistency with the underlying service call.
async def get_stream_status(

Comment thread wrappers/rest-api/README.md
Comment thread wrappers/rest-api/README.md
Comment thread wrappers/rest-api/app/core/auth.py Outdated
fake_users_db = {
"admin": {
"username": "admin",
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", # "password"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this password?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just placeholders for future use in case password authentication will be required in the rest api

Comment thread wrappers/rest-api/app/core/security.py Outdated
from typing import Any, Optional

# from jose import jwt
#from passlib.context import CryptContext

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 2 commented lines are needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just placeholders for future use in case password authentication will be required in the rest api

Comment thread wrappers/rest-api/app/core/security.py Outdated

from app.core.config import get_settings

#pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for all other commented out lines in this file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same answer :)
I can remove but then it will be little bit more dificult to find it in the future.

from time import time
from .pyrealsense_mock import context, create_mock_device

# # Global variables for frame generation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is all of this commented out code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing code, will remove.

@Nir-Az
Nir-Az requested a review from AviaAv April 29, 2025 14:25
physical_port = None

try:
usb_type = dev.get_info(rs.camera_info.usb_type_descriptor)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to wrap each get info with (dev.supports()) condition,
Here for example it will fail for MIPI devices as they do not support USB_type
I am not sure if it will throw

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np. will check it.

#!/bin/bash

# Start the FastAPI server
uvicorn main:combined_app --host 0.0.0.0 --port 8000 No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an option to do --reload for a fast reload, maybe adding it will make working on the wrapper easier?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reload is a flag for debugging purposes. not needed for regular usage.

Comment thread wrappers/rest-api/README.md
Comment thread wrappers/rest-api/app/services/rs_manager.py
This fixture will automatically be used in all tests.
"""
# Create mock instances
rs_manager = RealSenseManager()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we initialize sio and do RealSenseManager(sio) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a mock code

Comment thread wrappers/rest-api/app/models/device.py Outdated
@AviaAv

AviaAv commented May 5, 2025

Copy link
Copy Markdown
Contributor

We also need to add License and Copyright on some of the files

# License: Apache 2.0. See LICENSE file in root directory.
# Copyright(c) 2025 Intel Corporation. All Rights Reserved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        if device_id not in self.devices:
            self.refresh_devices()
            if device_id not in self.devices:
                raise RealSenseError(
                    status_code=404, detail=f"Device {device_id} not found"
                )

I see this code (or similar variations) are repeated multiple times in the code, let's use get_device or a new helper function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I agree it can be an improvement, but let's keep it simple for the first step, and do it in the future code changes.

@Nir-Az

Nir-Az commented May 18, 2025

Copy link
Copy Markdown
Collaborator

@ArthurRaizIntel can we progress here?
We want it merged in the next release

@Nir-Az
Nir-Az merged commit 4e38bff into realsenseai:development Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants