Open Source Developer Network

Build. Share.
Keep it open.

OCCDN ist ein Portal für freie Entwickler, Open-Source-Games und Software. Projekte in JavaScript, C, C++, Python und Node.js – offen zum Lernen, Forken, Weiterbauen und Teilen.

JavaScript C C++ Python Node.js OpenGL
occdn://developer-network
$ git clone https://github.com/d4brain
 public repositories found
 source code available
 community forum online

const occdn = {
  games: "open",
  software: "open",
  ideas: "welcome"
};


// Build something worth sharing.

Hier entsteht eine kleine JSON-API ausschließlich mit Node.js-Bordmitteln. Das macht Request-Routing, Statuscodes und Datenfluss transparent.

Startprompt

Erstelle mit dem eingebauten http-Modul eine REST-API für Notizen. Implementiere GET /api/notes und POST /api/notes, JSON-Parsing, Fehlerbehandlung und CORS für einen lokalen Client.

Datei: server.js

const http=require('node:http');
const notes=[{id:1,text:'Erstes Vibe-Coding-Beispiel'}];
function send(res,status,data){
 res.writeHead(status,{'Content-Type':'application/json; charset=utf-8','Access-Control-Allow-Origin':'*'});
 res.end(JSON.stringify(data));
}
const server=http.createServer(function(req,res){
 if(req.method==='GET' && req.url==='/api/notes')return send(res,200,notes);
 if(req.method==='POST' && req.url==='/api/notes'){
  let body='';
  req.on('data',function(chunk){body+=chunk;if(body.length>1e6)req.destroy()});
  req.on('end',function(){
   try{
    const input=JSON.parse(body);
    if(typeof input.text!=='string'||!input.text.trim())return send(res,400,{error:'text ist erforderlich'});
    const note={id:Date.now(),text:input.text.trim()};notes.push(note);send(res,201,note);
   }catch(error){send(res,400,{error:'Ungültiges JSON'})}
  });
  return;
 }
 send(res,404,{error:'Nicht gefunden'});
});
server.listen(3000,function(){console.log('API: http://localhost:3000/api/notes')});

Starten und testen

node server.js
curl http://localhost:3000/api/notes
curl -X POST http://localhost:3000/api/notes -H "Content-Type: application/json" -d "{"text":"API testen"}"

Prüfliste

  • GET liefert Status 200 und ein Array.
  • POST liefert Status 201.
  • Leerer Text und kaputtes JSON liefern Status 400.
  • Unbekannte Routen liefern Status 404.

Nächste Schritte

  • DELETE-Route ergänzen
  • Daten in einer Datei oder SQLite speichern
  • Tests mit dem eingebauten Node-Test-Runner schreiben
WHY OCCDN

Code should be usable,
not hidden.

OCCDN bündelt freie Software, spielbare Experimente und Quellcode an einem Ort. Der Fokus liegt auf nachvollziehbaren Projekten, direktem Zugriff und einer Community, die Ideen nicht nur diskutiert, sondern baut.

✓ Frei zugängliche Projekte ✓ Quellcode zum Forken ✓ Direkte spielbare Builds ✓ Austausch im Forum