<commit_before>var application_root = __dirname,
express = require('express'),
bodyParser = require('body-parser'),
path = require('path'),
mongoose = require('mongoose');

var app = express();

app.use(express.static(path.join(application_root, 'site')));
app.use(bodyParser());

var port = 4711;

app.listen( port, function() {
  console.log( 'Express server listening on port %d in %s mode', port, app.settings.env );
});

app.get( '/api', function( request, response ) {
  response.send( 'Library API is running' );
});

//Connect to database
mongoose.connect( 'mongodb://localhost/library_database' );

//Schemas
var Book = new mongoose.Schema({
  title: String,
  author: String,
  releaseDate: Date
});

//Models
var BookModel = mongoose.model( 'Book', Book );

// Configure server
app.configure( function() {
  //parses request body and populates request.body
  app.use( express.bodyParser() );

  //checks request.body for HTTP method overrides
  app.use( express.methodOverride() );

  //perform route lookup based on url and HTTP method
  app.use( app.router );

  //Where to serve static content
  app.use( express.static( path.join( application_root, 'site') ) );

  //Show all errors in development
  app.use( express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.get('/api/books', function(request,response) {
  return BookModel.find(function(err, books){
    if (!err) {
      return response.send(books);
    } else
      return console.log(err);
  });
});

app.post( '/api/books', function( request, response ) {
    var book = new BookModel({
        title: request.body.title,
        author: request.body.author,
        releaseDate: request.body.releaseDate
    });

    return book.save( function( err ) {
        if( !err ) {
            console.log( 'created' );
            return response.send( book );
            } else {
                console.log( err );
            }
    });
});

app.get('/api/books/:id', function(request, response){
  return BookModel.findById(request.params.id, function(err, book){
    if (!err) {
      return response.send(book);
    } else {
      return console.log(err);
    }
  });
});<commit_msg>REST api working correctly<commit_after>var application_root = __dirname,
express = require('express'),
bodyParser = require('body-parser'),
path = require('path'),
mongoose = require('mongoose');

var app = express();

app.use(express.static(path.join(application_root, 'site')));
app.use(bodyParser());

var port = 4711;

app.listen( port, function() {
  console.log( 'Express server listening on port %d in %s mode', port, app.settings.env );
});

app.get( '/api', function( request, response ) {
  response.send( 'Library API is running' );
});

//Connect to database
mongoose.connect( 'mongodb://localhost/library_database' );

//Schemas
var Book = new mongoose.Schema({
  title: String,
  author: String,
  releaseDate: Date
});

//Models
var BookModel = mongoose.model( 'Book', Book );

// Configure server
app.configure( function() {
  //parses request body and populates request.body
  app.use( express.bodyParser() );

  //checks request.body for HTTP method overrides
  app.use( express.methodOverride() );

  //perform route lookup based on url and HTTP method
  app.use( app.router );

  //Where to serve static content
  app.use( express.static( path.join( application_root, 'site') ) );

  //Show all errors in development
  app.use( express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.get('/api/books', function(request,response) {
  return BookModel.find(function(err, books){
    if (!err) {
      return response.send(books);
    } else
      return console.log(err);
  });
});

app.post( '/api/books', function( request, response ) {
    var book = new BookModel({
        title: request.body.title,
        author: request.body.author,
        releaseDate: request.body.releaseDate
    });

    return book.save( function( err ) {
        if( !err ) {
            console.log( 'created' );
            return response.send( book );
            } else {
                console.log( err );
            }
    });
});

app.get('/api/books/:id', function(request, response){
  return BookModel.findById(request.params.id, function(err, book){
    if (!err) {
      return response.send(book);
    } else {
      return console.log(err);
    }
  });
});

app.put( '/api/books/:id', function( request, response ) {
    console.log( 'Updating book ' + request.body.title );
    return BookModel.findById( request.params.id, function( err, book ) {
        book.title = request.body.title;
        book.author = request.body.author;
        book.releaseDate = request.body.releaseDate;

        return book.save( function( err ) {
            if( !err ) {
                console.log( 'book updated' );
            return response.send( book );
        } else {
            console.log( err );
        }
        });
    });
});

app.delete( '/api/books/:id', function( request, response ) {
    console.log( 'Deleting book with id: ' + request.params.id );
    return BookModel.findById( request.params.id, function( err, book ) {
        return book.remove( function( err ) {
            if( !err ) {
                console.log( 'Book removed' );
                return response.send( '' );
            } else {
                console.log( err );
            }
        });
    });
});
{'fraction_non_alphanumeric': 0.15216586449463163, 'fraction_numerical': 0.001480932987782303, 'mean_word_length': 2.8022519352568613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4436485', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1615, 'n_words': 418}