Make a Component Aware of Its Record Context explains how to do this:
import { LightningElement, api } from 'lwc';
export default class TestClass extends LightningElement {
@api recordId;
}
Make sure you pay close attention; LWC is case sensitive.
From there, you just load the data with getRecord:
import { LightningElement, wire, api } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import CONTACT_FIRST_NAME from '@salesforce/schema/Contact.FirstName';
export default class MyClass extends LightningElement {
@api recordId;
@wire(getRecord, { recordId: '$recordId', fields: [CONTACT_FIRST_NAME] }) contactRecord;
get contactName() {
return getFieldValue(this.contactRecord.data, CONTACT_FIRST_NAME);
}
}
This is basically what you described, but leveraging Lightning Data Service (LDS) to load the data for you.