slogan3

description

Helpt bij het maken van een duidelijke, gestandaardiseerde API-definitie die de communicatie tussen ontwikkelaars verbetert, automatische documentatie en tests ondersteunt, en het genereren van client-SDK's faciliteert. Dit patroon zorgt voor consistentie en maakt het onderhoud en de doorontwikkeling van de API eenvoudiger dan bij ongedocumenteerde of ad-hoc ontwerpen.

prompt

Help mij een REST API te ontwerpen met het OpenAPI Specificatiepatroon om mijn API-eindpunten, verzoek- en antwoordschema's en authenticatiemethoden helder te definiëren. Mijn API-doel: <voer het doel va ...

try_prompt

generate_helper
disclaimerOnPageApi

ai_answers

provider: openai
model: gpt-4.1-nano
Natuurlijk! Hier is een overzicht van hoe je een REST API kunt ontwerpen met het OpenAPI-specificatiepatroon voor jouw e-commerce platform, inclusief structuur, voorbeelden en best practices. ### 1. Structuur van het OpenAPI-document Een standaard OpenAPI-specificatie (v2.0 of v3.0) bestaat uit secties zoals: - **openapi / swagger**: Versie van de specificatie - **info**: Metadata (titel, versie, beschrijving) - **servers**: Basis-URL(s) van je API - **paths**: Definities van eindpunten - **components**: Herbruikbare schemas, security schemes, parameters, etc. - **security**: Globale authenticatie-instellingen - **tags**: Categorisatie van eindpunten - **externalDocs**: Documentatie buiten de specificatie ### 2. Voorbeeldstructuur (voorbeeld in YAML) ```yaml openapi: 3.0.3 info: title: E-commerce API version: 1.0.0 description: API voor beheer van gebruikersaccounts en bestellingen servers: - url: https://api.mijnwinkel.nl/v1 description: Productie server tags: - name: Gebruikers description: Beheer van gebruikersaccounts - name: Bestellingen description: Beheer van bestellingen components: schemas: Gebruiker: type: object properties: id: type: string naam: type: string email: type: string rol: type: string enum: [klant, admin] Bestelling: type: object properties: id: type: string gebruikerId: type: string producten: type: array items: $ref: '#/components/schemas/Product' status: type: string enum: [in behandeling, verzonden, afgeleverd] Product: type: object properties: id: type: string naam: type: string prijs: type: number format: float securitySchemes: BearerAuth: type: http scheme: bearer bearerFormat: JWT security: - BearerAuth: [] paths: /gebruikers: get: tags: - Gebruikers summary: Lijst van gebruikers responses: '200': description: Succes content: application/json: schema: type: array items: $ref: '#/components/schemas/Gebruiker' security: - BearerAuth: [] post: tags: - Gebruikers summary: Nieuwe gebruiker aanmaken requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/Gebruiker' responses: '201': description: Gebruiker aangemaakt content: application/json: schema: $ref: '#/components/schemas/Gebruiker' /gebruikers/{id}: get: tags: - Gebruikers summary: Details van een gebruiker parameters: - name: id in: path required: true schema: type: string responses: '200': description: Gebruiker details content: application/json: schema: $ref: '#/components/schemas/Gebruiker' '404': description: Gebruiker niet gevonden put: tags: - Gebruikers summary: Gebruiker bijwerken parameters: - name: id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/Gebruiker' responses: '200': description: Gebruiker bijgewerkt '404': description: Gebruiker niet gevonden delete: tags: - Gebruikers summary: Gebruiker verwijderen parameters: - name: id in: path required: true schema: type: string responses: '204': description: Verwijderd # Zelfde structuur voor bestellingen ``` ### 3. Veelvoorkomende definities en voorbeelden - **Schemas**: definieer herbruikbare objectstructuren (zoals Gebruiker, Bestelling) - **Path parameters**: gebruik `{id}` voor resource-specifieke eindpunten - **Request bodies**: voor POST/PUT - **Responses**: standaardstatuscodes en datatypes - **Authenticatie**: definieer securitySchemes (bijv. JWT Bearer tokens) - **Error handling**: definieer foutberichten voor invalid requests ### 4. Best practices voor onderhoud en doorontwikkeling - **Modulariseer**: scheid schemas, security, en parameters in `components` voor hergebruik - **Gebruik tags**: voor categorisatie en overzichtelijkheid - **Versiebeheer**: houd API-versies bij (bijv. v1, v2) in de URL of via headers - **Consistentie**: gebruik consistente naamgeving en statuscodes - **Documenteer foutcodes**: voeg bij elke foutstatus duidelijke beschrijvingen toe - **Automatiseer validatie**: gebruik tools zoals Swagger UI, OpenAPI Generator - **Regelmatige updates**: werk de specificatie bij als je API wijzigt, en communiceer breaking changes - **Test je API**: met mock servers en unit tests op de specificatie ### Samenvatting - Structuur je OpenAPI-bestand overzichtelijk met secties voor schemas, paths, security, etc. - Gebruik herbruikbare componenten - Voeg duidelijke documentatie toe voor elke endpoint en response - Onderhoud de specificatie door consistent te blijven, te versioneren en te automatiseren Wil je een compleet voorbeeld of hulp bij het genereren van een volledige specificatie?
provider: deepseek
model: deepseek-chat
Zeker! Ik help je bij het ontwerpen van een REST API met OpenAPI voor jouw e-commerce platform. Hier is een gestructureerde handleiding: ## 1. OpenAPI Documentstructuur ```yaml openapi: 3.0.3 info: title: E-commerce Platform API description: API voor gebruikersaccounts en bestellingenbeheer version: 1.0.0 contact: name: API Team email: api@ecommerce-platform.nl servers: - url: https://api.ecommerce-platform.nl/v1 description: Productie server - url: https://sandbox.api.ecommerce-platform.nl/v1 description: Test server paths: # Hier komen alle endpoints /gebruikers: /bestellingen: components: # Hier komen herbruikbare componenten schemas: parameters: securitySchemes: responses: ``` ## 2. Authenticatie Methoden ```yaml components: securitySchemes: BearerAuth: type: http scheme: bearer bearerFormat: JWT ApiKeyAuth: type: apiKey in: header name: X-API-Key security: - BearerAuth: [] # Of voor specifieke endpoints: # - ApiKeyAuth: [] ``` ## 3. Gebruikersbeheer Endpoints ```yaml paths: /gebruikers: get: summary: Lijst van gebruikers ophalen description: Haalt een gepagineerde lijst van gebruikers op security: - BearerAuth: [] parameters: - $ref: '#/components/parameters/PaginatieLimit' - $ref: '#/components/parameters/PaginatieOffset' responses: '200': description: Succesvolle response content: application/json: schema: $ref: '#/components/schemas/GebruikersLijst' '401': $ref: '#/components/responses/Ongeautoriseerd' post: summary: Nieuwe gebruiker aanmaken requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/NieuweGebruiker' responses: '201': description: Gebruiker succesvol aangemaakt content: application/json: schema: $ref: '#/components/schemas/Gebruiker' /gebruikers/{gebruikerId}: get: summary: Specifieke gebruiker ophalen parameters: - $ref: '#/components/parameters/GebruikerId' responses: '200': description: Succesvolle response content: application/json: schema: $ref: '#/components/schemas/Gebruiker' ``` ## 4. Bestellingen Endpoints ```yaml paths: /bestellingen: get: summary: Bestellingen ophalen security: - BearerAuth: [] parameters: - $ref: '#/components/parameters/PaginatieLimit' - name: status in: query schema: type: string enum: [actief, voltooid, geannuleerd] responses: '200': description: Succesvolle response content: application/json: schema: $ref: '#/components/schemas/BestellingenLijst' post: summary: Nieuwe bestelling plaatsen security: - BearerAuth: [] requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/NieuweBestelling' responses: '201': description: Bestelling succesvol geplaatst content: application/json: schema: $ref: '#/components/schemas/Bestelling' ``` ## 5. Component Definitions ```yaml components: schemas: Gebruiker: type: object required: - id - email - voornaam - achternaam properties: id: type: string format: uuid example: "123e4567-e89b-12d3-a456-426614174000" email: type: string format: email voornaam: type: string achternaam: type: string telefoon: type: string adres: $ref: '#/components/schemas/Adres' NieuweGebruiker: type: object required: - email - wachtwoord - voornaam - achternaam properties: email: type: string format: email wachtwoord: type: string format: password minLength: 8 voornaam: type: string achternaam: type: string Bestelling: type: object required: - id - gebruikerId - producten - totaalBedrag - status properties: id: type: string format: uuid gebruikerId: type: string format: uuid producten: type: array items: $ref: '#/components/schemas/BesteldProduct' totaalBedrag: type: number format: float minimum: 0 status: type: string enum: [actief, voltooid, geannuleerd] Adres: type: object properties: straat: type: string huisnummer: type: string postcode: type: string plaats: type: string land: type: string default: "Nederland" parameters: GebruikerId: name: gebruikerId in: path required: true schema: type: string format: uuid PaginatieLimit: name: limit in: query schema: type: integer minimum: 1 maximum: 100 default: 20 PaginatieOffset: name: offset in: query schema: type: integer minimum: 0 default: 0 responses: Ongeautoriseerd: description: Authenticatie vereist of ongeldig token NietGevonden: description: Resource niet gevonden Validatiefout: description: Ongeldige invoer parameters ``` ## 6. Best Practices voor Onderhoud en Ontwikkeling ### Versiebeheer - Gebruik semantische versienummers (bijv. 1.0.0 → 1.1.0) - Houd breaking changes tot een minimum - Gebruik API versioning in URL of headers ### Documentatie ```yaml info: title: E-commerce Platform API description: | # API Documentatie Deze API beheert gebruikersaccounts en bestellingen. ## Authenticatie Gebruik JWT tokens voor authenticatie. ## Rate Limiting Maximaal 1000 requests per uur per gebruiker. version: "1.0.0" termsOfService: https://example.nl/terms ``` ### Validatie en Tools - Gebruik Swagger Editor voor real-time validatie - Implementeer OpenAPI linter in CI/CD pipeline - Gebruik tools zoals Redoc of Swagger UI voor documentatie ### Wijzigingen Beheren - Houd een CHANGELOG.md bij - Gebruik `deprecated: true` voor verouderde endpoints - Communiceer wijzigingen tijdig naar API consumers ### Herbruikbaarheid - Definieer gemeenschappelijke componenten in `components` - Gebruik `$ref` voor hergebruik - Standaardiseer foutresponses ### Security ```yaml components: securitySchemes: OAuth2: type: oauth2 flows: authorizationCode: authorizationUrl: https://example.nl/oauth/authorize tokenUrl: https://example.nl/oauth/token scopes: gebruikers:lezen: "Gebruikersgegevens lezen" bestellingen:schrijven: "Bestellingen plaatsen" ``` Deze structuur biedt een solide basis voor jouw e-commerce API en maakt toekomstige uitbreidingen eenvoudig. Begin met de kernfunctionaliteit en breid geleidelijk uit op basis van je requirements.