Error code

Selamat pagi teman-teman,

Pada post kali ini saya akan menjelaskan error code yang digunakan dalam pembuatan API untuk kelompok PPLA3:

Error code

  1. Method GET dan berhasil mengembalikan objek yang diinginkan, kembalikan status 200 OK. Contoh implementasi: return Response::json($attendances,200);
  2. Method POST dan berhasil menyimpan objek baru ke database, kembalikan status 201 Created. Jika gagal menyimpan ke database, kembalikan status 500 Internal Server Error. Contoh implementasi:
    $success=$log_point->save();
    if(!$success) {
    return Response::json(“error saving”,500);
    }
    else
    return Response::json($log_point,201);
  3. Method POST dan berhasil mengembalikan objek yang diinginkan, kembalikan status 200 OK. Contoh implementasi:
    public function checkout()
    {
    $id = Input::get(‘id’);
    $history=History::find($id);
    if($history != null) {
    $history->time_checkout = Carbon::now()->toDayDateTimeString();
    $success=$history->save();
    if(!$success)
    return Response::json(“error updating”,500);
    return Response::json(“success”,201);
    } else {
    return Response::json(“error”,500);
    }
    }

Sumber:
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
http://agung-setiawan.com/laravel-rest-api/
https://laravel.com/docs/5.4/errors

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s