@nldoc/api
v2.0.1
Published
API client and React hooks for NLdoc backend services.
Readme
@nldoc/api
API client and React hooks for NLdoc backend services.
Installation
npm install @nldoc/apiUsage
useApiClient
A React hook that creates an API client instance for communicating with NLdoc backend services.
import { useApiClient } from '@nldoc/api'
function MyComponent() {
const apiClient = useApiClient('https://nldoc.nl/api')
// or use a relative path
const apiClient = useApiClient('/api')
// apiClient will be null if no route is provided
if (!apiClient) return null
// Use the client...
}Parameters:
apiRoute: string | null | undefined- The API route URL. Can be:- An absolute URL (e.g.,
'https://nldoc.nl/api') - A relative path (e.g.,
'/api') - will be resolved relative to the current window location nullorundefined- returnsnull
- An absolute URL (e.g.,
Returns: APIClient | null
useConversion
A React hook for converting documents using NLdoc's Conversion API.
import { useConversion, ContentType } from '@nldoc/api'
function MyComponent() {
const file = new Blob([JSON.stringify(myDocument)], { type: ContentType.Tiptap })
const apiRoute = 'https://nldoc.nl/api'
const conversion = useConversion(file, ContentType.HTML, apiRoute)
// conversion.status can be: 'idle' | 'converting' | 'converted' | 'error'
if (conversion.status === 'converted') {
console.log(conversion.result) // The converted document
}
}Parameters:
file: Blob | null- The file to convertto: string- The target content type (useContentTypeconstants)apiRoute: string | null | undefined- The API route URL
Returns: UseConversion - An object containing the conversion status and result
Content Types
The package exports common content type constants:
import { ContentType } from '@nldoc/api'
ContentType.HTML // 'text/html'
ContentType.Tiptap // 'application/vnd.nldoc+json'
// ... and moreLicense
EUPL-1.2
